SYS/BIOS
7.00
|
Static and run-time memory manager.
All memory allocations are performed either by Memory_alloc (or its varients Memory_calloc, Memory_valloc, etc.) at run-time.
Run-time memory management is performed by modules that implement the ti/sysbios/runtime/IHeap.h interface. The Memory module itself simply provides a common interface for any variety of system and application specific memory management policies implemented by IHeap modules.
Heap instances are created statically or dynamically via heap specific create functions and these instances are then passed as an input parameter to the Memory calls that have an IHeap_Handle parameter.
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <ti/sysbios/runtime/Error.h>
#include <ti/sysbios/runtime/IHeap.h>
Go to the source code of this file.
Data Structures | |
struct | Memory_Stats |
Memory heap statistics. More... | |
Macros | |
#define | Memory_Q_BLOCKING (1) |
Blocking quality. More... | |
Typedefs | |
typedef void *(* | IHeap_AllocFxn) (void *, size_t, size_t, Error_Block *) |
typedef void(* | IHeap_FreeFxn) (void *, void *, size_t) |
typedef bool(* | IHeap_IsBlockingFxn) (void *) |
typedef void(* | IHeap_GetStatsFxn) (void *, Memory_Stats *) |
Functions | |
void * | Memory_alloc (IHeap_Handle heap, size_t size, size_t align, Error_Block *eb) |
Allocate a block of memory from a heap. More... | |
void * | Memory_calloc (IHeap_Handle heap, size_t size, size_t align, Error_Block *eb) |
Allocate a block of memory from a heap and zero out the contents. More... | |
void | Memory_free (IHeap_Handle heap, void *block, size_t size) |
Frees the space if the heap manager offers such functionality. More... | |
size_t | Memory_getMaxDefaultTypeAlign (void) |
Return the largest alignment required by the target. More... | |
void | Memory_getStats (IHeap_Handle heap, Memory_Stats *stats) |
Obtain statistics from a heap. More... | |
bool | Memory_query (IHeap_Handle heap, int qual) |
Test for a particular heap quality. More... | |
IHeap_Handle | Memory_getDefaultHeap (void) |
Get the default heap handle. More... | |
void | Memory_setDefaultHeap (IHeap_Handle heap) |
Set the default heap handle. More... | |
void * | Memory_valloc (IHeap_Handle heap, size_t size, size_t align, char value, Error_Block *eb) |
Allocate a block of memory from a heap and initialize the contents to the value specified. More... | |
Variables | |
IHeap_Handle | Memory_defaultHeapInstance |
The default heap. More... | |
#define Memory_Q_BLOCKING (1) |
Blocking quality.
Heaps with this "quality" may cause the calling thread to block; i.e., suspend execution until another thread leaves the gate.
typedef void*(* IHeap_AllocFxn) (void *, size_t, size_t, Error_Block *) |
typedef void(* IHeap_FreeFxn) (void *, void *, size_t) |
typedef bool(* IHeap_IsBlockingFxn) (void *) |
typedef void(* IHeap_GetStatsFxn) (void *, Memory_Stats *) |
void* Memory_alloc | ( | IHeap_Handle | heap, |
size_t | size, | ||
size_t | align, | ||
Error_Block * | eb | ||
) |
Allocate a block of memory from a heap.
The heap is created by a module that implements the ti/sysbios/runtime/IHeap.h interface. If heap is NULL, the Memory_defaultHeapInstance is used.
A value of 0 denotes maximum default type alignment.
If the allocation was successful, Memory_alloc() returns non-NULL pointer to the allocated and uninitialized block; otherwise it returns NULL and the error block will indicate the cause of the error.
heap | heap from which the memory is allocated |
size | requested memory block size (in MADUs) |
align | alignment (in MADUs) of the block of memory |
eb | pointer to error block |
pointer | to allocated memory (NULL on failure) |
void* Memory_calloc | ( | IHeap_Handle | heap, |
size_t | size, | ||
size_t | align, | ||
Error_Block * | eb | ||
) |
Allocate a block of memory from a heap and zero out the contents.
The heap is created by a module that implements the ti/sysbios/runtime/IHeap.h interface. If heap is NULL, the Memory_defaultHeapInstance is used.
A value of 0 denotes maximum default type alignment.
If the allocation was successful, Memory_calloc() returns non-NULL pointer to the allocated and initialized block; otherwise it returns NULL and the error block will indicate the cause of the error.
heap | heap from which the memory is allocated |
size | requested memory block size (in MADUs) |
align | alignment (in MADUs) of the block of memory |
eb | pointer to error block |
pointer | to allocated memory (NULL on failure) |
void Memory_free | ( | IHeap_Handle | heap, |
void * | block, | ||
size_t | size | ||
) |
Frees the space if the heap manager offers such functionality.
The heap is created by a module that implements the ti/sysbios/runtime/IHeap.h interface. If heap is NULL, the Memory_defaultHeapInstance is used.
heap | heap that the block of memory will be freed back to. |
block | block of memory to free back to the heap |
size | size (in MADUs) of the block of memory to free. |
size_t Memory_getMaxDefaultTypeAlign | ( | void | ) |
Return the largest alignment required by the target.
Returns the largest alignment required for all the standard base types supported by the current target
Returns | target-specific alignment in MADUs. |
void Memory_getStats | ( | IHeap_Handle | heap, |
Memory_Stats * | stats | ||
) |
Obtain statistics from a heap.
The heap is created by a module that implements the ti/sysbios/runtime/IHeap.h interface. If heap is NULL, the Memory_defaultHeapInstance is used.
heap | the heap to get the statistics from |
stats | the output buffer for the returned statistics |
bool Memory_query | ( | IHeap_Handle | heap, |
int | qual | ||
) |
Test for a particular heap quality.
There currently is only one quality, namely Memory_Q_BLOCKING.
The heap is created by a module that implements the ti/sysbios/runtime/IHeap.h interface. If heap is NULL, the Memory_defaultHeapInstance is queried
For example: Memory_Q_BLOCKING.
If heap has the "qual" quality, this method returns true, otherwise it returns false.
heap | the heap to query |
qual | quality to test |
quality |
IHeap_Handle Memory_getDefaultHeap | ( | void | ) |
Get the default heap handle.
When Memory_alloc(), etc. are passed 'NULL' as the heap parameter, the default heap is used. This API can be used to get the default heap handle.
void Memory_setDefaultHeap | ( | IHeap_Handle | heap | ) |
Set the default heap handle.
When Memory_alloc(), etc. are passed 'NULL' as the heap parameter, the default heap is used. This API can be used to set this default handle to a user defined heap. Note that most use cases can be managed with the BIOS.heapType and BIOS.heapSize configuration parameters.
void* Memory_valloc | ( | IHeap_Handle | heap, |
size_t | size, | ||
size_t | align, | ||
char | value, | ||
Error_Block * | eb | ||
) |
Allocate a block of memory from a heap and initialize the contents to the value specified.
The heap is created by a module that implements the ti/sysbios/runtime/IHeap.h interface. If heap is NULL, the Memory_defaultHeapInstance is used.
A value of 0 denotes maximum default type alignment.
If the allocation was successful, Memory_valloc() returns non-NULL pointer to the allocated and initialized block; otherwise it returns NULL
and the error block will indicate the cause of the error.
heap | heap from which the memory is allocated |
size | requested memory block size (in MADUs) |
align | alignment (in MADUs) of the block of memory |
value | value to initialize the contents of the block |
eb | pointer to error block |
pointer | to allocated memory (NULL on failure) |
IHeap_Handle Memory_defaultHeapInstance |
The default heap.
If no heap is specified in the Memory module's methods (i.e. heap == NULL) defaultHeapInstance is used.