Mistake on this page?
Report an issue in GitHub or email us
Macros
Heap and memory pools

Macros

#define MEM_LIBC_MALLOC   0
 MEM_LIBC_MALLOC==1: Use malloc/free/realloc provided by your C-library instead of the lwip internal allocator. More...
 
#define MEMP_MEM_MALLOC   0
 MEMP_MEM_MALLOC==1: Use mem_malloc/mem_free instead of the lwip pool allocator. More...
 
#define MEMP_MEM_INIT   0
 MEMP_MEM_INIT==1: Force use of memset to initialize pool memory. More...
 
#define MEM_ALIGNMENT   1
 MEM_ALIGNMENT: should be set to the alignment of the CPU 4 byte alignment -> #define MEM_ALIGNMENT 4 2 byte alignment -> #define MEM_ALIGNMENT 2. More...
 
#define MEM_SIZE   1600
 MEM_SIZE: the size of the heap memory. More...
 
#define MEMP_OVERFLOW_CHECK   0
 MEMP_OVERFLOW_CHECK: memp overflow protection reserves a configurable amount of bytes before and after each memp element in every pool and fills it with a prominent default value. More...
 
#define MEMP_SANITY_CHECK   0
 MEMP_SANITY_CHECK==1: run a sanity check after each memp_free() to make sure that there are no cycles in the linked lists. More...
 
#define MEM_OVERFLOW_CHECK   0
 MEM_OVERFLOW_CHECK: mem overflow protection reserves a configurable amount of bytes before and after each heap allocation chunk and fills it with a prominent default value. More...
 
#define MEM_SANITY_CHECK   0
 MEM_SANITY_CHECK==1: run a sanity check after each mem_free() to make sure that the linked list of heap elements is not corrupted. More...
 
#define MEM_USE_POOLS   0
 MEM_USE_POOLS==1: Use an alternative to malloc() by allocating from a set of memory pools of various sizes. More...
 
#define MEM_USE_POOLS_TRY_BIGGER_POOL   0
 MEM_USE_POOLS_TRY_BIGGER_POOL==1: if one malloc-pool is empty, try the next bigger pool - WARNING: THIS MIGHT WASTE MEMORY but it can make a system more reliable. More...
 
#define MEMP_USE_CUSTOM_POOLS   0
 MEMP_USE_CUSTOM_POOLS==1: whether to include a user file lwippools.h that defines additional pools beyond the "standard" ones required by lwIP. More...
 
#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT   0
 Set this to 1 if you want to free PBUF_RAM pbufs (or call mem_free()) from interrupt context (or another context that doesn't allow waiting for a semaphore). More...
 

Detailed Description

Macro Definition Documentation

#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT   0

Set this to 1 if you want to free PBUF_RAM pbufs (or call mem_free()) from interrupt context (or another context that doesn't allow waiting for a semaphore).

If set to 1, mem_malloc will be protected by a semaphore and SYS_ARCH_PROTECT, while mem_free will only use SYS_ARCH_PROTECT. mem_malloc SYS_ARCH_UNPROTECTs with each loop so that mem_free can run.

ATTENTION: As you can see from the above description, this leads to dis-/ enabling interrupts often, which can be slow! Also, on low memory, mem_malloc can need longer.

If you don't want that, at least for NO_SYS=0, you can still use the following functions to enqueue a deallocation call which then runs in the tcpip_thread context:

  • pbuf_free_callback(p);
  • mem_free_callback(m);

Definition at line 389 of file opt.h.

#define MEM_ALIGNMENT   1

MEM_ALIGNMENT: should be set to the alignment of the CPU 4 byte alignment -> #define MEM_ALIGNMENT 4 2 byte alignment -> #define MEM_ALIGNMENT 2.

Definition at line 289 of file opt.h.

#define MEM_LIBC_MALLOC   0

MEM_LIBC_MALLOC==1: Use malloc/free/realloc provided by your C-library instead of the lwip internal allocator.

Can save code size if you already use it.

Definition at line 258 of file opt.h.

#define MEM_OVERFLOW_CHECK   0

MEM_OVERFLOW_CHECK: mem overflow protection reserves a configurable amount of bytes before and after each heap allocation chunk and fills it with a prominent default value.

MEM_OVERFLOW_CHECK == 0 no checking MEM_OVERFLOW_CHECK == 1 checks each element when it is freed MEM_OVERFLOW_CHECK >= 2 checks all heap elements every time mem_malloc() or mem_free() is called (useful but slow!)

Definition at line 331 of file opt.h.

#define MEM_SANITY_CHECK   0

MEM_SANITY_CHECK==1: run a sanity check after each mem_free() to make sure that the linked list of heap elements is not corrupted.

Definition at line 339 of file opt.h.

#define MEM_SIZE   1600

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.

Definition at line 297 of file opt.h.

#define MEM_USE_POOLS   0

MEM_USE_POOLS==1: Use an alternative to malloc() by allocating from a set of memory pools of various sizes.

When mem_malloc is called, an element of the smallest pool that can provide the length needed is returned. To use this, MEMP_USE_CUSTOM_POOLS also has to be enabled.

Definition at line 349 of file opt.h.

#define MEM_USE_POOLS_TRY_BIGGER_POOL   0

MEM_USE_POOLS_TRY_BIGGER_POOL==1: if one malloc-pool is empty, try the next bigger pool - WARNING: THIS MIGHT WASTE MEMORY but it can make a system more reliable.

Definition at line 357 of file opt.h.

#define MEMP_MEM_INIT   0

MEMP_MEM_INIT==1: Force use of memset to initialize pool memory.

Useful if pool are moved in uninitialized section of memory. This will ensure default values in pcbs struct are well initialized in all conditions.

Definition at line 280 of file opt.h.

#define MEMP_MEM_MALLOC   0

MEMP_MEM_MALLOC==1: Use mem_malloc/mem_free instead of the lwip pool allocator.

Especially useful with MEM_LIBC_MALLOC but handle with care regarding execution speed (heap alloc can be much slower than pool alloc) and usage from interrupts (especially if your netif driver allocates PBUF_POOL pbufs for received frames from interrupt)! ATTENTION: Currently, this uses the heap for ALL pools (also for private pools, not only for internal pools defined in memp_std.h)!

Definition at line 271 of file opt.h.

#define MEMP_OVERFLOW_CHECK   0

MEMP_OVERFLOW_CHECK: memp overflow protection reserves a configurable amount of bytes before and after each memp element in every pool and fills it with a prominent default value.

MEMP_OVERFLOW_CHECK == 0 no checking MEMP_OVERFLOW_CHECK == 1 checks each element when it is freed MEMP_OVERFLOW_CHECK >= 2 checks each element in every pool every time memp_malloc() or memp_free() is called (useful but slow!)

Definition at line 310 of file opt.h.

#define MEMP_SANITY_CHECK   0

MEMP_SANITY_CHECK==1: run a sanity check after each memp_free() to make sure that there are no cycles in the linked lists.

Definition at line 318 of file opt.h.

#define MEMP_USE_CUSTOM_POOLS   0

MEMP_USE_CUSTOM_POOLS==1: whether to include a user file lwippools.h that defines additional pools beyond the "standard" ones required by lwIP.

If you set this to 1, you must have lwippools.h in your include path somewhere.

Definition at line 367 of file opt.h.

Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.