19#if defined(WITH_LWIP) && MEMP_USE_CUSTOM_POOLS
26coap_malloc_type_string(
size_t size) {
27 void *ptr = mem_malloc(size +
sizeof(
size_t));
30 unsigned int *s_ptr = (
unsigned int *)ptr;
31 u_char *b_ptr = (u_char *)ptr;
34 return b_ptr +
sizeof(
unsigned int);
40coap_realloc_type_string(
void *p,
size_t size) {
42 unsigned int *s_ptr = (
unsigned int *)p;
47 new = mem_malloc(size +
sizeof(
unsigned int));
50 u_char *b_ptr = (u_char *)
new;
52 s_ptr = (
unsigned int *)
new;
55 unsigned int *o_ptr = (
unsigned int *)p;
58 memcpy(b_ptr +
sizeof(
unsigned int), p, *o_ptr);
59 coap_free_type_string(o_ptr);
61 return b_ptr +
sizeof(
unsigned int);
67coap_free_type_string(
void *p) {
68 u_char *ptr = (u_char *)p;
71 mem_free(ptr -
sizeof(
unsigned int));
79#if MEMP_STATS && LWIP_STATS_DISPLAY && MEMP_USE_CUSTOM_POOLS
86 coap_log(log_level,
"* LwIP custom memory pools information\n");
92 for (i = 0; i < MEMP_MAX; i++) {
94 if (!strcmp(
"COAP_STRING", memp_pools[i]->stats->name))
97 coap_log(log_level,
"* %-17s avail %3d in-use %3d peak %3d failed %3d\n",
98 memp_pools[i]->stats->name, memp_pools[i]->stats->avail,
99 memp_pools[i]->stats->used, memp_pools[i]->stats->max,
100 memp_pools[i]->stats->err);
107#elif defined(WITH_LWIP) && ! MEMP_USE_CUSTOM_POOLS && ! MEM_LIBC_MALLOC
111#if COAP_MEMORY_TYPE_TRACK
123 void *ptr = mem_malloc(size +
sizeof(
size_t));
126#if COAP_MEMORY_TYPE_TRACK
129 track_counts[type]++;
130 if (track_counts[type] > peak_counts[type])
131 peak_counts[type] = track_counts[type];
137 size_t *s_ptr = (
size_t *)ptr;
138 u_char *b_ptr = (u_char *)ptr;
141 return b_ptr +
sizeof(size_t);
148 void *
new = mem_malloc(size +
sizeof(
size_t));
151#if COAP_MEMORY_TYPE_TRACK
155 track_counts[type]++;
156 if (track_counts[type] > peak_counts[type])
157 peak_counts[type] = track_counts[type];
163 size_t *s_ptr = (
size_t *)
new;
164 u_char *b_ptr = (u_char *)
new;
168 size_t *o_ptr = (
size_t *)p;
171 memcpy(b_ptr +
sizeof(
size_t), p, *o_ptr);
173 return b_ptr +
sizeof(size_t);
180 u_char *ptr = (u_char *)p;
183#if COAP_MEMORY_TYPE_TRACK
186 track_counts[type]--;
189 mem_free(ptr -
sizeof(
size_t));
193#define MAKE_CASE(n) case n: name = #n; break
196#if COAP_MEMORY_TYPE_TRACK
199 coap_log(level,
"* Memory type counts\n");
201 const char *name =
"?";
238 coap_log(level,
"* %-20s in-use %3d peak %3d failed %2d\n",
239 name, track_counts[i], peak_counts[i], fail_counts[i]);
Library specific build wrapper for coap_internal.h.
void coap_dump_memory_type_counts(coap_log_t 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().
coap_log_t coap_get_log_level(void)
Get the current logging level.
#define coap_log(level,...)
Logging function.