nRF51 SDK - S130 SoftDevice
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Memory Manager

Memory Manager for the nRF51 SDK. More...

Functions

uint32_t nrf51_sdk_mem_init (void)
 Initializes Memory Manager. More...
 
uint32_t nrf51_sdk_mem_alloc (uint8_t **pp_buffer, uint32_t *p_size)
 Allocates dynamic memory. More...
 
uint32_t nrf51_sdk_mem_free (uint8_t *p_buffer)
 Frees allocated memory. More...
 

Detailed Description

Memory Manager for the nRF51 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 pools of fixed sizes. These pools can be requested for usage, and freed when the application no longer needs them. To make usage of static buffers efficient, three pools of static buffers are created: small, medium, and large. The size of each of the pools and the count of blocks in them can be configured based on the application requirements in the configuration file sdk_config.h. To disable any of the pools, define the block count to be zero.

Function Documentation

uint32_t nrf51_sdk_mem_alloc ( uint8_t **  pp_buffer,
uint32_t *  p_size 
)

Allocates dynamic memory.

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.

Parameters
[out]pp_bufferPointer to the allocated memory block if memory allocation succeeds; otherwise pointer to NULL.
[in,out]p_sizeSize of memory requested by the application. Based on which block is assigned, this parameter returns the actual size available to the application.
Return values
NRF_SUCCESSIf memory was successfully allocated. Otherwise, an error code that indicates the reason for the failure is returned.
NRF_ERROR_INVALID_PARAMIf the requested memory size is zero or larger than the largest memory block that the module is configured to support.
NRF_ERROR_NO_MEMIf the requested memory size is larger than the largest memory block that is available.
uint32_t nrf51_sdk_mem_free ( uint8_t *  p_buffer)

Frees allocated memory.

API to resubmit memory allocated for the application by the Memory Manager back to the Memory Manager, so that it can be reassigned.

Parameters
[out]p_bufferPointer to the memory block that is resubmitted.
Return values
NRF_SUCCESSIf memory was successfully freed. Otherwise, an error code that indicates the reason for the failure is returned.
NRF_ERROR_INVALID_ADDRIf the memory that was requested to be freed is not managed by the Memory Manager.
uint32_t nrf51_sdk_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.