diff --git a/CHANGELOG b/CHANGELOG index 80c54a3d..263e1880 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,6 +19,11 @@ HISTORY ++ New features: + 2009-02-11 Simon Goldschmidt (suggested by Gottfried Spitaler) + * opt.h, memp.h/.c: added MEMP_MEM_MALLOC to use mem_malloc/mem_free instead + of the pool allocator (can save code size with MEM_LIBC_MALLOC if libc-malloc + is otherwise used) + 2009-01-28 Jonathan Larmour (suggested by Bill Bauerbach) * ipv4/inet_chksum.c, ipv4/lwip/inet_chksum.h: inet_chksum_pseudo_partial() is only used by UDPLITE at present, so conditionalise it. diff --git a/src/core/memp.c b/src/core/memp.c index 16a91894..01793ab5 100644 --- a/src/core/memp.c +++ b/src/core/memp.c @@ -56,6 +56,8 @@ #include +#if !MEMP_MEM_MALLOC /* don't build if not configured for use in lwipopts.h */ + struct memp { struct memp *next; #if MEMP_OVERFLOW_CHECK @@ -109,8 +111,14 @@ struct memp { * Elements form a linked list. */ static struct memp *memp_tab[MEMP_MAX]; +#else /* MEMP_MEM_MALLOC */ + +#define MEMP_ALIGN_SIZE(x) (LWIP_MEM_ALIGN_SIZE(x)) + +#endif /* MEMP_MEM_MALLOC */ + /** This array holds the element sizes of each pool. */ -#if !MEM_USE_POOLS +#if !MEM_USE_POOLS && !MEMP_MEM_MALLOC static #endif const u16_t memp_sizes[MEMP_MAX] = { @@ -118,6 +126,8 @@ const u16_t memp_sizes[MEMP_MAX] = { #include "lwip/memp_std.h" }; +#if !MEMP_MEM_MALLOC /* don't build if not configured for use in lwipopts.h */ + /** This array holds the number of elements in each pool. */ static const u16_t memp_num[MEMP_MAX] = { #define LWIP_MEMPOOL(name,num,size,desc) (num), @@ -368,3 +378,5 @@ memp_free(memp_t type, void *mem) SYS_ARCH_UNPROTECT(old_level); } + +#endif /* MEMP_MEM_MALLOC */ diff --git a/src/include/lwip/memp.h b/src/include/lwip/memp.h index a0438633..45b1f39b 100644 --- a/src/include/lwip/memp.h +++ b/src/include/lwip/memp.h @@ -73,10 +73,22 @@ typedef enum { We use this helper type and these defines so we can avoid using const memp_t values */ #define MEMP_POOL_FIRST ((memp_t) MEMP_POOL_HELPER_FIRST) #define MEMP_POOL_LAST ((memp_t) MEMP_POOL_HELPER_LAST) - -extern const u16_t memp_sizes[MEMP_MAX]; #endif /* MEM_USE_POOLS */ +#if MEMP_MEM_MALLOC || MEM_USE_POOLS +extern const u16_t memp_sizes[MEMP_MAX]; +#endif /* MEMP_MEM_MALLOC || MEM_USE_POOLS */ + +#if MEMP_MEM_MALLOC + +#include "mem.h" + +#define memp_init() +#define memp_malloc(type) mem_malloc(memp_sizes[type]) +#define memp_free(type, mem) mem_free(mem) + +#else /* MEMP_MEM_MALLOC */ + void memp_init(void); #if MEMP_OVERFLOW_CHECK @@ -87,6 +99,8 @@ void *memp_malloc(memp_t type); #endif void memp_free(memp_t type, void *mem); +#endif /* MEMP_MEM_MALLOC */ + #ifdef __cplusplus } #endif diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 0eb57b6f..907a9582 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -98,6 +98,15 @@ #define MEM_LIBC_MALLOC 0 #endif +/** +* 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 and usage from interrupts! +*/ +#ifndef MEMP_MEM_MALLOC +#define MEMP_MEM_MALLOC 0 +#endif + /** * MEM_ALIGNMENT: should be set to the alignment of the CPU * 4 byte alignment -> #define MEM_ALIGNMENT 4 @@ -1120,7 +1129,7 @@ */ #ifndef RECV_BUFSIZE_DEFAULT #define RECV_BUFSIZE_DEFAULT INT_MAX -#endif /* RECV_BUFSIZE_DEFAULT */ +#endif /** * SO_REUSE==1: Enable SO_REUSEADDR and SO_REUSEPORT options. DO NOT USE!