Functions for controlling memory object.
More...
Functions for controlling memory object.
Macro for creating a nrf_memobj pool.
Macro declares nrf_balloc object. Element in the pool contains user defined data part and memobj header.
#define NRF_MEMOBJ_STD_HEADER_SIZE sizeof(uint32_t) |
Memory object can consist of multiple object with the same size. Each object has header and data part. First element in memory object is memory object head which has special header, remaining objects has the same header. Model of memory object is presented below.
|------------------—| |------------------—| |------------------—| | head header (u32): | —>| std header - p_next |----—>| p_memobj_pool | | num_of_chunks, | | |------------------—| |------------------—|
ref counter | | | | | |
std header - p_next | - | | | .... | |
------------------— | | data | | data |
data | | | | |
| | | | |
------------------— | | ------------------— | | ------------------— |
head mid_element last_element
Function for allocating memobj with requested size.
Fixed length elements in the pool are linked together to provide amount of memory requested by the user. If memory object is successfully allocated then user can use memory however it is fragmented into multiple object so it has to be access through the API: nrf_memobj_write, nrf_memobj_read.
This function initializes the pool.
- Parameters
-
[in] | p_pool | Pointer to the memobj pool instance structure. |
[in] | size | Data size of requested object. |
- Returns
- Pointer to memory object or NULL if requested size cannot be allocated.
Function for forcing freeing of the memory object.
- Note
- This function should be use with caution because it can lead to undefined behavior of the modules since modules using the memory object are not aware that it has been freed.
- Parameters
-
[in] | p_obj | Pointer to memory object. |
Function for indicating that memory object is used and cannot be freed.
Memory object can be shared and reused between multiple modules and this mechanism ensures that object is freed when no longer used by any module. Memory object has a counter which is incremented whenever this function is called. nrf_memobj_put function decrements the counter.
- Parameters
-
[in] | p_obj | Pointer to memory object. |
Function for initializing the memobj pool instance.
This function initializes the pool.
- Parameters
-
[in] | p_pool | Pointer to the memobj pool instance structure. |
- Returns
- NRF_SUCCESS on success, otherwise error code.
Function for indicated that memory object is no longer used by the module and can be freed if no other module is using it.
Memory object is returned to the pool if internal counter reaches 0 after decrementing. It means that no other module is needing it anymore.
- Note
- Memory object holds pointer to the pool which was used to allocate it so it does not have to be provided explicitly to this function.
- Parameters
-
[in] | p_obj | Pointer to memory object. |
void nrf_memobj_read |
( |
nrf_memobj_t * |
p_obj, |
|
|
void * |
p_data, |
|
|
uint32_t |
len, |
|
|
uint32_t |
offset |
|
) |
| |
Function for reading data from the memory object.
- Parameters
-
[in] | p_obj | Pointer to memory object. |
[in] | p_data | Pointer to the destination buffer. |
[in] | len | Amount of data to be read from the memory object. |
[in] | offset | Offset. |
void nrf_memobj_write |
( |
nrf_memobj_t * |
p_obj, |
|
|
void * |
p_data, |
|
|
uint32_t |
len, |
|
|
uint32_t |
offset |
|
) |
| |
Function for writing data to the memory object.
- Parameters
-
[in] | p_obj | Pointer to memory object. |
[in] | p_data | Pointer to data to be written to the memory object. |
[in] | len | Amount of data to be written to the memory object. |
[in] | offset | Offset. |