nRF5 IoT SDK  v0.9.0
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Memory Manager

Memory Manager for the nRFXX SDK. More...

Functions

uint32_t nrf_mem_init (void)
 Initializes Memory Manager. More...
 
uint32_t nrf_mem_reserve (uint8_t **pp_buffer, uint32_t *p_size)
 Reserves a block of memory for the application. More...
 
void * nrf_malloc (uint32_t size)
 'malloc' styled memory allocation function. More...
 
void * nrf_calloc (uint32_t nmemb, uint32_t size)
 'calloc' styled memory allocation function. More...
 
void nrf_free (void *p_buffer)
 Free allocated memory - standard 'free' styles API. More...
 
void * nrf_realloc (void *p_buffer, uint32_t size)
 Memory reallocation (trim) function. More...
 

Detailed Description

Memory Manager for the nRFXX SDK.

This module allows for dynamic use of memory. Currently, this module can be used only to allocate and free memory in the RAM.

The Memory Manager manages static memory blocks of fixed sizes. These blocks can be requested for usage, and freed when the application no longer needs them. A maximum of seven block categories can be managed by the module. These block categories are identified by xxsmall, xmall, small, medium, large, xlarge, and xxlarge. They are ordered in increasing block sizes. The size and the count of each of the block categories can be configured based on the application requirements in the configuration file sdk_config.h. To use fewer than seven buffer pools, do not define the count for the unwanted block or explicitly set it to zero. At least one block category must be configured for this module to function as expected.

Function Documentation

void* nrf_calloc ( uint32_t  nmemb,
uint32_t  size 
)

'calloc' styled memory allocation function.

API to allocate zero-initialized memory of size count*size.

Parameters
[in]nmembNumber of elements of 'size' bytes.
[in]sizeSize of each element allocated.
Return values
Valid,zero-initializedmemory location if the procedure was successful, else, NULL.
void nrf_free ( void *  p_buffer)

Free allocated memory - standard 'free' styles API.

API to resubmit memory allocated, same in functionality nrf_free.

Parameters
[out]p_bufferPointer to the memory block that is being freed.
void* nrf_malloc ( uint32_t  size)

'malloc' styled memory allocation function.

API to allocate memory, same as nrf_mem_reserve but uses malloc signature.

Parameters
[in]sizeRequested memory size.
Return values
Validmemory location if the procedure was successful, else, NULL.
uint32_t nrf_mem_init ( void  )

Initializes Memory Manager.

API to initialize the Memory Manager. Always call this API before using any of the other APIs of the module. This API should be called only once.

Return values
NRF_SUCCESSIf initialization was successful. Otherwise, an error code that indicates the reason for the failure is returned.
Warning
If this API fails, the application shall not proceed with using other APIs of this module.
uint32_t nrf_mem_reserve ( uint8_t **  pp_buffer,
uint32_t *  p_size 
)

Reserves a block of memory for the application.

API to request a contiguous memory block of the given length. If the memory allocation succeeds, pp_buffer points to the memory block. If the memory allocation fails, pp_buffer points to NULL and the return value of the API indicates the reason for the failure. The memory block reserved using this API can be freed using the nrf_free function.

Parameters
[out]pp_bufferPointer to the allocated memory block if memory allocation succeeds; otherwise points to NULL.
[in,out]p_sizeRequested memory size. This parameter returns the actual size allocated. If the procedure was successful, the actual size returned is always greater than or equal to requested size, never less.
Return values
NRF_SUCCESSIf memory was successfully allocated. Otherwise, an error code indicating the reason for failure.
NRF_ERROR_INVALID_PARAMIf the requested memory size is zero or greater than the largest memory block that the module is configured to support.
NRF_ERROR_NO_MEMIf there is no memory available of the requested size.
void* nrf_realloc ( void *  p_buffer,
uint32_t  size 
)

Memory reallocation (trim) function.

API to reallocate memory or to trim it. Trim is mentioned here to avoid use of API to request memory size larger than original memory allocated.

Parameters
[in]p_bufferPointer to the memory block that needs to be trimmed.
[in]sizeSize of memory at the beginning of the buffer to be left untrimmed.
Return values
Pointerto memory location with trimmed size, else, NULL.