SYS/BIOS
7.00
|
Multiple fixed size buffer heap manager.
The HeapMultiBuf manager provides functions to allocate and free storage from a heap of type HeapMultiBuf which inherits from IHeap. HeapMultiBuf manages multiple fixed-size memory buffers. Each buffer contains a fixed number of allocable memory 'blocks' of the same size. Simply put, a HeapMultiBuf instance manages a collection of HeapBuf instances. HeapMultiBuf is intended as a fast and deterministic memory manager which can service requests for blocks of arbitrary size.
An example HeapMultiBuf instance might have sixteen 32-byte blocks in one buffer, and four 128-byte blocks in another buffer. A request for memory will be serviced by the smallest possible block, so a request for 100 bytes would receive a 128-byte block in our example.
Allocating from HeapMultiBuf will try to return a block from the first buffer which has:
AND
If the first matching buffer is empty, HeapMultiBuf will only continue searching for a block if 'block borrowing' is enabled (see Block Borrowing).
The following configuration code creates a HeapMultiBuf instance which manages 3 pools of 10 blocks each, with block sizes of 64, 128 and 256.
Function | Hwi | Swi | Task | Main | Startup |
---|---|---|---|---|---|
Params_init | Y | Y | Y | Y | Y |
alloc | Y | Y | Y | Y | N |
construct | N* | N* | Y | Y | N |
create | N* | N* | Y | Y | N |
delete | N* | N* | Y | Y | N |
destruct | N* | N* | Y | Y | N |
free | Y | Y | Y | Y | N |
getStats | Y | Y | Y | Y | N |
isBlocking | Y | Y | Y | Y | N |
Definitions:
|
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <ti/sysbios/heaps/HeapBuf.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 | HeapMultiBuf_Params |
struct | HeapMultiBuf_Struct |
Macros | |
#define | HeapMultiBuf_A_blockNotFreed "Invalid block address on the free. Failed to free block back to heap." |
Invalid block pointer. More... | |
#define | HeapMultiBuf_E_size "requested size is too big: handle=0x%x, size=%u" |
Raised when requested size exceeds all blockSizes. More... | |
#define | ti_sysbios_heaps_HeapMultiBuf_Handle_upCast(handle) ((IHeap_Handle)(handle)) |
cast handle to an IHeap_Handle for use by Memory_alloc, etc. More... | |
Typedefs | |
typedef struct HeapMultiBuf_Struct * | HeapMultiBuf_Handle |
typedef HeapMultiBuf_Struct | HeapMultiBuf_Object |
Functions | |
void * | HeapMultiBuf_alloc (HeapMultiBuf_Handle handle, size_t size, size_t align, Error_Block *eb) |
HeapMultiBuf will return a block that is >= 'size' with an alignment that is >= 'align'. The HeapMultiBuf will attempt to service a request for any size; the specified size does not need to match the configured block sizes of the buffers. More... | |
void | HeapMultiBuf_free (HeapMultiBuf_Handle handle, void *buf, size_t size) |
HeapMultiBuf ignores the 'size' parameter to free. It determines the correct buffer to free the block to by comparing addresses. More... | |
bool | HeapMultiBuf_isBlocking (HeapMultiBuf_Handle handle) |
This function always returns false since the alloc/free never block on a resource. More... | |
void | HeapMultiBuf_getStats (HeapMultiBuf_Handle handle, Memory_Stats *statBuf) |
get memory stats for a HeapMultiBuf object More... | |
HeapMultiBuf_Handle | HeapMultiBuf_create (const HeapMultiBuf_Params *params, Error_Block *eb) |
Create a HeapMultiBuf heap. More... | |
HeapMultiBuf_Handle | HeapMultiBuf_construct (HeapMultiBuf_Struct *obj, const HeapMultiBuf_Params *params, Error_Block *eb) |
Construct a HeapMultiBuf heap. More... | |
void | HeapMultiBuf_delete (HeapMultiBuf_Handle *handle) |
Delete a HeapMultiBuf heap. More... | |
void | HeapMultiBuf_destruct (HeapMultiBuf_Struct *obj) |
Destruct a HeapMultiBuf heap. More... | |
void | HeapMultiBuf_Params_init (HeapMultiBuf_Params *prms) |
Initialize the HeapMultiBuf_Params structure with default values. More... | |
HeapMultiBuf_Handle | HeapMultiBuf_Object_first (void) |
return handle of the first HeapMultiBuf on HeapMultiBuf list More... | |
HeapMultiBuf_Handle | HeapMultiBuf_Object_next (HeapMultiBuf_Handle heap) |
return handle of the next HeapMultiBuf on HeapMultiBuf list More... | |
#define HeapMultiBuf_A_blockNotFreed "Invalid block address on the free. Failed to free block back to heap." |
Invalid block pointer.
This Assert is raised if a call to free does not successfully free the block back to any of the buffers. Indicates that the block pointer is invalid, or that the HeapMultiBuf state has been corrupted.
#define HeapMultiBuf_E_size "requested size is too big: handle=0x%x, size=%u" |
Raised when requested size exceeds all blockSizes.
#define ti_sysbios_heaps_HeapMultiBuf_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 HeapMultiBuf_Struct * HeapMultiBuf_Handle |
void* HeapMultiBuf_alloc | ( | HeapMultiBuf_Handle | handle, |
size_t | size, | ||
size_t | align, | ||
Error_Block * | eb | ||
) |
HeapMultiBuf will return a block that is >= 'size' with an alignment that is >= 'align'. The HeapMultiBuf will attempt to service a request for any size; the specified size does not need to match the configured block sizes of the buffers.
void HeapMultiBuf_free | ( | HeapMultiBuf_Handle | handle, |
void * | buf, | ||
size_t | size | ||
) |
HeapMultiBuf ignores the 'size' parameter to free. It determines the correct buffer to free the block to by comparing addresses.
bool HeapMultiBuf_isBlocking | ( | HeapMultiBuf_Handle | handle | ) |
This function always returns false since the alloc/free never block on a resource.
void HeapMultiBuf_getStats | ( | HeapMultiBuf_Handle | handle, |
Memory_Stats * | statBuf | ||
) |
get memory stats for a HeapMultiBuf object
handle | heap handle |
statBuf | pointer to a Memory_Stats object |
HeapMultiBuf_Handle HeapMultiBuf_create | ( | const HeapMultiBuf_Params * | params, |
Error_Block * | eb | ||
) |
Create a HeapMultiBuf
heap.
params | optional parameters |
eb | error block |
HeapMultiBuf | handle (NULL on failure) |
HeapMultiBuf_Handle HeapMultiBuf_construct | ( | HeapMultiBuf_Struct * | obj, |
const HeapMultiBuf_Params * | params, | ||
Error_Block * | eb | ||
) |
Construct a HeapMultiBuf
heap.
HeapMultiBuf_construct is equivalent to HeapMultiBuf_create except that the HeapMultiBuf_Struct is pre-allocated.
obj | pointer to a HeapMultiBuf object |
params | optional parameters |
eb | error block |
HeapMultiBuf | handle (NULL on failure) |
void HeapMultiBuf_delete | ( | HeapMultiBuf_Handle * | handle | ) |
Delete a HeapMultiBuf
heap.
Note that HeapMultiBuf_delete takes a pointer to a HeapMultiBuf_Handle which enables HeapMultiBuf_delete to set the HeapMultiBuf handle to NULL.
handle | pointer to a HeapMultiBuf handle |
void HeapMultiBuf_destruct | ( | HeapMultiBuf_Struct * | obj | ) |
Destruct a HeapMultiBuf
heap.
obj | pointer to a HeapMultiBuf objects |
void HeapMultiBuf_Params_init | ( | HeapMultiBuf_Params * | prms | ) |
Initialize the HeapMultiBuf_Params structure with default values.
HeapMultiBuf_Params_init initializes the HeapMultiBuf_Params structure with default values. HeapMultiBuf_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 |
HeapMultiBuf_Handle HeapMultiBuf_Object_first | ( | void | ) |
return handle of the first HeapMultiBuf on HeapMultiBuf list
Return the handle of the first HeapMultiBuf on the create/construct list. NULL if no HeapMultiBufs have been created or constructed.
HeapMultiBuf | handle |
HeapMultiBuf_Handle HeapMultiBuf_Object_next | ( | HeapMultiBuf_Handle | heap | ) |
return handle of the next HeapMultiBuf on HeapMultiBuf list
Return the handle of the next HeapMultiBuf on the create/construct list. NULL if no more HeapMultiBufs are on the list.
heap | HeapMultiBuf handle |
HeapMultiBuf | handle |