mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2026-05-26 18:17:10 +08:00
Introduced the option MEM_USE_POOLS to use 4 pools with different sized elements instead of a heap. This both prevents memory fragmentation and gives a higher speed at the cost of more memory consumption. Turned off by default.
This commit is contained in:
@@ -66,11 +66,21 @@ typedef u16_t mem_size_t;
|
||||
#define mem_realloc(x, size) realloc(x,size)
|
||||
#endif
|
||||
#else /* MEM_LIBC_MALLOC */
|
||||
#if MEM_USE_POOLS
|
||||
/** The pool implementation of the heap currently uses 4 pools */
|
||||
#define MEM_POOL_COUNT 4
|
||||
/** mem_init is not used when using pools instead of a heap */
|
||||
#define mem_init()
|
||||
/** mem_realloc is not used when using pools instead of a heap:
|
||||
we can't free part of a pool element and don't want to copy the rest */
|
||||
#define mem_realloc(mem, size) (mem)
|
||||
#else /* MEM_USE_POOLS */
|
||||
/* lwIP alternative malloc */
|
||||
void mem_init(void);
|
||||
void *mem_realloc(void *mem, mem_size_t size);
|
||||
#endif /* MEM_USE_POOLS */
|
||||
void *mem_malloc(mem_size_t size);
|
||||
void mem_free(void *mem);
|
||||
void *mem_realloc(void *mem, mem_size_t size);
|
||||
#endif /* MEM_LIBC_MALLOC */
|
||||
|
||||
#ifndef LWIP_MEM_ALIGN_SIZE
|
||||
|
||||
@@ -56,6 +56,12 @@ typedef enum {
|
||||
#endif
|
||||
MEMP_PBUF_POOL,
|
||||
MEMP_SYS_TIMEOUT,
|
||||
#if MEM_USE_POOLS
|
||||
MEMP_MEM_POOL_1,
|
||||
MEMP_MEM_POOL_2,
|
||||
MEMP_MEM_POOL_3,
|
||||
MEMP_MEM_POOL_4,
|
||||
#endif
|
||||
|
||||
MEMP_MAX
|
||||
} memp_t;
|
||||
@@ -70,6 +76,10 @@ void *memp_malloc(memp_t type);
|
||||
#endif
|
||||
void memp_free(memp_t type, void *mem);
|
||||
|
||||
#if MEM_USE_POOLS
|
||||
extern const u16_t memp_sizes[MEMP_MAX];
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -66,6 +66,8 @@
|
||||
#endif
|
||||
|
||||
/* ---------- Memory options ---------- */
|
||||
/* Use malloc/free/realloc provided by your C-library instead of the
|
||||
lwip internal allocator. Can save code size if you already use it. */
|
||||
#ifndef MEM_LIBC_MALLOC
|
||||
#define MEM_LIBC_MALLOC 0
|
||||
#endif
|
||||
@@ -73,13 +75,51 @@
|
||||
/* MEM_ALIGNMENT: should be set to the alignment of the CPU for which
|
||||
lwIP is compiled. 4 byte alignment -> define MEM_ALIGNMENT to 4, 2
|
||||
byte alignment -> define MEM_ALIGNMENT to 2. */
|
||||
|
||||
#ifndef MEM_ALIGNMENT
|
||||
#define MEM_ALIGNMENT 1
|
||||
#endif
|
||||
|
||||
/* Memory can be allocated from 4 pools with element of different size.
|
||||
When mem_malloc is called, and element of the smallest pool that can
|
||||
provide the lenght needed is returned. */
|
||||
#ifndef MEM_USE_POOLS
|
||||
#define MEM_USE_POOLS 0
|
||||
#endif
|
||||
|
||||
#if MEM_USE_POOLS
|
||||
/* The element sizes of the 4 pools.
|
||||
The sizes must be increasing, e.g. the elements in pool 2 must be
|
||||
bigger than the elements in pool 1 and so on. If this is not the case,
|
||||
mem_malloc will not work correctly. */
|
||||
#ifndef MEM_POOL_SIZE_1
|
||||
#error You must have at least one pool if MEM_USE_POOLS is set to 1!
|
||||
#endif
|
||||
#ifndef MEM_POOL_SIZE_2
|
||||
#define MEM_POOL_SIZE_2 0
|
||||
#endif
|
||||
#ifndef MEM_POOL_SIZE_3
|
||||
#define MEM_POOL_SIZE_3 0
|
||||
#endif
|
||||
#ifndef MEM_POOL_SIZE_4
|
||||
#define MEM_POOL_SIZE_4 0
|
||||
#endif
|
||||
/* The element count of the 4 pools */
|
||||
#ifndef MEM_POOL_NUM_1
|
||||
#error You must have at least one pool if MEM_USE_POOLS is set to 1!
|
||||
#endif
|
||||
#ifndef MEM_POOL_NUM_2
|
||||
#define MEM_POOL_NUM_2 0
|
||||
#endif
|
||||
#ifndef MEM_POOL_NUM_3
|
||||
#define MEM_POOL_NUM_3 0
|
||||
#endif
|
||||
#ifndef MEM_POOL_NUM_4
|
||||
#define MEM_POOL_NUM_4 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* MEM_SIZE: the size of the heap memory. If the application will send
|
||||
a lot of data that needs to be copied, this should be set high. */
|
||||
a lot of data that needs to be copied, this should be set high. */
|
||||
#ifndef MEM_SIZE
|
||||
#define MEM_SIZE 1600
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user