SYS/BIOS
7.00
|
Growth-only based heap implementation.
HeapMin
is a minimal footprint heap implementation. This module is is designed for applications that only create module instances and generally only allocate memory at runtime, but never delete created instances or free memory explicitly.
When calling HeapMin_create() at runtime, the client is responsible for aligning the buffer.
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <ti/sysbios/knl/Queue.h>
#include <ti/sysbios/runtime/Error.h>
#include <ti/sysbios/runtime/IHeap.h>
#include <ti/sysbios/runtime/Memory.h>
Go to the source code of this file.
Data Structures | |
struct | HeapMin_Struct |
struct | HeapMin_Params |
Macros | |
#define | HeapMin_A_zeroSize "heap size must be > 0" |
Assert that the heap size is non-zero on the create. More... | |
#define | HeapMin_E_freeError "free() invalid in growth-only HeapMin" |
Error raised if HeapMin_free() is called. More... | |
#define | HeapMin_Handle_upCast(handle) ((IHeap_Handle)(handle)) |
cast handle to an IHeap_Handle for use by Memory_alloc, etc. More... | |
Typedefs | |
typedef struct HeapMin_Struct | HeapMin_Object |
typedef struct HeapMin_Struct * | HeapMin_Handle |
Functions | |
void * | HeapMin_alloc (void *handle, size_t size, size_t align, Error_Block *eb) |
Allocate a block of memory from the heap. More... | |
void | HeapMin_free (void *handle, void *buf, size_t size) |
Free a block of memory back to the heap. More... | |
bool | HeapMin_isBlocking (void *handle) |
Can this heap block the caller. More... | |
void | HeapMin_getStats (void *handle, Memory_Stats *statBuf) |
get memory stats for a HeapMin object More... | |
HeapMin_Handle | HeapMin_create (const HeapMin_Params *params, Error_Block *eb) |
Create a HeapMin heap. More... | |
HeapMin_Handle | HeapMin_construct (HeapMin_Struct *obj, const HeapMin_Params *params) |
Construct a HeapMin heap. More... | |
void | HeapMin_delete (HeapMin_Handle *handle) |
Delete a HeapMin heap. More... | |
void | HeapMin_destruct (HeapMin_Struct *obj) |
Destruct a HeapMin heap. More... | |
void | HeapMin_Params_init (HeapMin_Params *prms) |
Initialize the HeapMin_Params structure with default values. More... | |
HeapMin_Handle | HeapMin_Object_first (void) |
return handle of the first HeapMin on HeapMin list More... | |
HeapMin_Handle | HeapMin_Object_next (HeapMin_Handle heap) |
return handle of the next HeapMin on HeapMin list More... | |
#define HeapMin_A_zeroSize "heap size must be > 0" |
Assert that the heap size is non-zero on the create.
#define HeapMin_E_freeError "free() invalid in growth-only HeapMin" |
Error raised if HeapMin_free() is called.
This error is only raised if a HeapMin_free() is called and the HeapMin.freeError configuration parameter is set to true.
#define HeapMin_Handle_upCast | ( | handle | ) | ((IHeap_Handle)(handle)) |
cast handle to an IHeap_Handle for use by Memory_alloc, etc.
handle | heap handle |
IHeap_Handle |
typedef struct HeapMin_Struct HeapMin_Object |
typedef struct HeapMin_Struct * HeapMin_Handle |
void* HeapMin_alloc | ( | void * | handle, |
size_t | size, | ||
size_t | align, | ||
Error_Block * | eb | ||
) |
Allocate a block of memory from the heap.
void HeapMin_free | ( | void * | handle, |
void * | buf, | ||
size_t | size | ||
) |
Free a block of memory back to the heap.
This is a growth only heap. Calling the HeapMin_free
function will result in a HeapMin_E_freeError error unless the HeapMin.freeError configuration parameter is set to false
.
bool HeapMin_isBlocking | ( | void * | handle | ) |
Can this heap block the caller.
HeapMin
always returns false
since it never blocks on a resource.
handle | heap handle |
always | returns false |
void HeapMin_getStats | ( | void * | handle, |
Memory_Stats * | statBuf | ||
) |
get memory stats for a HeapMin object
handle | heap handle |
statBuf | pointer to a Memory_Stats object |
HeapMin_Handle HeapMin_create | ( | const HeapMin_Params * | params, |
Error_Block * | eb | ||
) |
Create a HeapMin
heap.
This heap is a growth-only heap that is intended to be used by systems that never delete objects or free memory. Objects can be created at runtime based on values determined at runtime, but objects can not be deleted.
params | optional parameters |
eb | error block |
HeapMin | handle (NULL on failure) |
HeapMin_Handle HeapMin_construct | ( | HeapMin_Struct * | obj, |
const HeapMin_Params * | params | ||
) |
Construct a HeapMin
heap.
HeapMin_construct is equivalent to HeapMin_create except that the HeapMin_Struct is pre-allocated.
obj | pointer to a HeapMin object |
params | optional parameters |
HeapMin | handle (NULL on failure) |
void HeapMin_delete | ( | HeapMin_Handle * | handle | ) |
Delete a HeapMin
heap.
Note that HeapMin_delete takes a pointer to a HeapMin_Handle which enables HeapMin_delete to set the HeapMin handle to NULL.
handle | pointer to a HeapMin handle |
void HeapMin_destruct | ( | HeapMin_Struct * | obj | ) |
Destruct a HeapMin
heap.
obj | pointer to a HeapMin objects |
void HeapMin_Params_init | ( | HeapMin_Params * | prms | ) |
Initialize the HeapMin_Params structure with default values.
HeapMin_Params_init initializes the HeapMin_Params structure with default values. HeapMin_Params_init should always be called before setting individual parameter fields. This allows new fields to be added in the future with compatible defaults – existing source code does not need to change when new fields are added.
prms | pointer to uninitialized params structure |
HeapMin_Handle HeapMin_Object_first | ( | void | ) |
return handle of the first HeapMin on HeapMin list
Return the handle of the first HeapMin on the create/construct list. NULL if no HeapMins have been created or constructed.
HeapMin | handle |
HeapMin_Handle HeapMin_Object_next | ( | HeapMin_Handle | heap | ) |
return handle of the next HeapMin on HeapMin list
Return the handle of the next HeapMin on the create/construct list. NULL if no more HeapMins are on the list.
heap | HeapMin handle |
HeapMin | handle |