libcoap 4.3.5-develop-72190a8
Loading...
Searching...
No Matches
coap_mem.h File Reference

CoAP memory handling. More...

#include "coap3/coap_oscore.h"
#include "coap3/coap_proxy.h"
#include <stdlib.h>
+ Include dependency graph for coap_mem.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  coap_memory_tag_t {
  COAP_STRING , COAP_ATTRIBUTE_NAME , COAP_ATTRIBUTE_VALUE , COAP_PACKET ,
  COAP_NODE , COAP_CONTEXT , COAP_ENDPOINT , COAP_PDU ,
  COAP_PDU_BUF , COAP_RESOURCE , COAP_RESOURCEATTR , COAP_DTLS_SESSION ,
  COAP_SESSION , COAP_OPTLIST , COAP_CACHE_KEY , COAP_CACHE_ENTRY ,
  COAP_LG_XMIT , COAP_LG_CRCV , COAP_LG_SRCV , COAP_DIGEST_CTX ,
  COAP_SUBSCRIPTION , COAP_DTLS_CONTEXT , COAP_OSCORE_COM , COAP_OSCORE_SEN ,
  COAP_OSCORE_REC , COAP_OSCORE_EX , COAP_OSCORE_EP , COAP_OSCORE_BUF ,
  COAP_COSE , COAP_MEM_TAG_LAST
}
 Type specifiers for coap_malloc_type(). More...
 

Functions

void coap_memory_init (void)
 Initializes libcoap's memory management.
 
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_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 pointer to the newly allocated memory of size.
 
void coap_free_type (coap_memory_tag_t type, void *p)
 Releases the memory that was allocated by coap_malloc_type().
 
void coap_dump_memory_type_counts (coap_log_t log_level)
 Dumps the current usage of malloc'd memory types.
 
COAP_STATIC_INLINE void * coap_malloc (size_t size)
 Wrapper function to coap_malloc_type() for backwards compatibility.
 
COAP_STATIC_INLINE void coap_free (void *object)
 Wrapper function to coap_free_type() for backwards compatibility.
 

Detailed Description

CoAP memory handling.

Definition in file coap_mem.h.

Enumeration Type Documentation

◆ coap_memory_tag_t

Type specifiers for coap_malloc_type().

Memory objects can be typed to facilitate arrays of type objects to be used instead of dynamic memory management on constrained devices.

Enumerator
COAP_STRING 
COAP_ATTRIBUTE_NAME 
COAP_ATTRIBUTE_VALUE 
COAP_PACKET 
COAP_NODE 
COAP_CONTEXT 
COAP_ENDPOINT 
COAP_PDU 
COAP_PDU_BUF 
COAP_RESOURCE 
COAP_RESOURCEATTR 
COAP_DTLS_SESSION 
COAP_SESSION 
COAP_OPTLIST 
COAP_CACHE_KEY 
COAP_CACHE_ENTRY 
COAP_LG_XMIT 
COAP_LG_CRCV 
COAP_LG_SRCV 
COAP_DIGEST_CTX 
COAP_SUBSCRIPTION 
COAP_DTLS_CONTEXT 
COAP_OSCORE_COM 
COAP_OSCORE_SEN 
COAP_OSCORE_REC 
COAP_OSCORE_EX 
COAP_OSCORE_EP 
COAP_OSCORE_BUF 
COAP_COSE 
COAP_MEM_TAG_LAST 

Definition at line 38 of file coap_mem.h.

Function Documentation

◆ coap_dump_memory_type_counts()

void coap_dump_memory_type_counts ( coap_log_t  log_level)

Dumps the current usage of malloc'd memory types.

Requires COAP_MEMORY_TYPE_TRACK to be defined to 1.

Parameters
log_levelThe logging level to use.

Definition at line 670 of file coap_mem.c.

+ Here is the caller graph for this function:

◆ coap_free()

COAP_STATIC_INLINE void coap_free ( void *  object)

Wrapper function to coap_free_type() for backwards compatibility.

Definition at line 132 of file coap_mem.h.

+ Here is the call graph for this function:

◆ coap_free_type()

void coap_free_type ( coap_memory_tag_t  type,
void *  p 
)

Releases the memory that was allocated by coap_malloc_type().

The type tag type must be the same that was used for allocating the object pointed to by .

Parameters
typeThe type of the object to release.
pA pointer to memory that was allocated by coap_malloc_type().
+ Here is the caller graph for this function:

◆ coap_malloc()

COAP_STATIC_INLINE void * coap_malloc ( size_t  size)

Wrapper function to coap_malloc_type() for backwards compatibility.

Definition at line 124 of file coap_mem.h.

+ Here is the call graph for this function:

◆ coap_malloc_type()

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.

The type is used to select the appropriate storage container on constrained devices. The storage allocated by coap_malloc_type() must be released with coap_free_type().

Parameters
typeThe type of object to be stored.
sizeThe number of bytes requested.
Returns
A pointer to the allocated storage or NULL on error.
+ Here is the caller graph for this function:

◆ coap_memory_init()

void coap_memory_init ( void  )

Initializes libcoap's memory management.

This function must be called once before coap_malloc() can be used on constrained devices.

+ Here is the caller graph for this function:

◆ coap_realloc_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 pointer to the newly allocated memory of size.

Only COAP_STRING type is supported.

Note: If there is an error, p will separately need to be released by coap_free_type().

Parameters
typeThe type of object to be stored.
pA pointer to memory that was allocated by coap_malloc_type().
sizeThe number of bytes requested.
Returns
A pointer to the allocated storage or NULL on error.
+ Here is the caller graph for this function: