74#if ! defined(WITH_LWIP) || (defined(WITH_LWIP) && ! MEMP_USE_CUSTOM_POOLS && ! MEM_USE_POOLS)
139#include <lwip/memp.h>
148coap_malloc_error(uint16_t *err) {
160void *coap_malloc_type_string(
size_t size);
162void *coap_realloc_type_string(
void *p,
size_t size);
164void coap_free_type_string(
void *p);
168#define coap_malloc_type(type, asize) \
169 (type == COAP_STRING) ? coap_malloc_type_string(asize) : \
170 (((asize) <= memp_pools[MEMP_ ## type]->size) ? \
171 memp_malloc(MEMP_ ## type) : coap_malloc_error(&memp_pools[MEMP_ ## type]->stats->err))
175#define coap_malloc_type(type, asize) \
176 (type == COAP_STRING) ? coap_malloc_type_string(asize) : \
177 (((asize) <= memp_pools[MEMP_ ## type]->size) ? \
178 memp_malloc(MEMP_ ## type) : NULL)
181#define coap_free_type(type, p) \
182 (type == COAP_STRING) ? coap_free_type_string(p) : \
183 memp_free(MEMP_ ## type, p)
186#define coap_realloc_type(type, p, asize) \
187 (type == COAP_STRING) ? coap_realloc_type_string(p, asize) : \
188 ((p) ? ((asize) <= memp_pools[MEMP_ ## type]->size) ? (p) : NULL : coap_malloc_type(type, asize))
194#define coap_malloc_type(type, asize) \
195 (((asize) <= memp_pools[MEMP_ ## type]->size) ? \
196 memp_malloc(MEMP_ ## type) : coap_malloc_error(&memp_pools[MEMP_ ## type]->stats->err))
200#define coap_malloc_type(type, asize) \
201 (((asize) <= memp_pools[MEMP_ ## type]->size) ? \
202 memp_malloc(MEMP_ ## type) : NULL)
205#define coap_free_type(type, p) memp_free(MEMP_ ## type, p)
208#define coap_realloc_type(type, p, asize) \
209 ((p) ? ((asize) <= memp_pools[MEMP_ ## type]->size) ? (p) : NULL : coap_malloc_type(type, asize))
218 LWIP_ASSERT(
"coap_malloc must not be used in lwIP", 0);
225 LWIP_ASSERT(
"coap_free must not be used in lwIP", 0);
COAP_STATIC_INLINE void coap_free(void *object)
Wrapper function to coap_free_type() for backwards compatibility.
COAP_STATIC_INLINE void * coap_malloc(size_t size)
Wrapper function to coap_malloc_type() for backwards compatibility.
void coap_dump_memory_type_counts(coap_log_t log_level)
Dumps the current usage of malloc'd memory types.
void coap_memory_init(void)
Initializes libcoap's memory management.
coap_memory_tag_t
Type specifiers for coap_malloc_type().
void * coap_realloc_type(coap_memory_tag_t type, void *p, size_t size)
Reallocates a chunk p of bytes created by coap_malloc_type() or coap_realloc_type() and returns a poi...
void * coap_malloc_type(coap_memory_tag_t type, size_t size)
Allocates a chunk of size bytes and returns a pointer to the newly allocated memory.
void coap_free_type(coap_memory_tag_t type, void *p)
Releases the memory that was allocated by coap_malloc_type().
Helper functions for proxy handling.
#define COAP_STATIC_INLINE