SYS/BIOS
7.00
|
Fixed size buffer heap manager.
The HeapBuf manager provides functions to allocate and free storage from a heap of type HeapBuf which inherits from IHeap. HeapBuf manages a single fixed-size buffer, split into equally sized allocable blocks.
The HeapBuf manager is intended as a very fast and deterministic memory manager which can only allocate blocks of a single size. It is ideal for managing a heap that is only used for allocating a single type of object, or for objects that have very similar sizes.
Allocation from and freeing to a HeapBuf instance is non-blocking and deterministic: a call to alloc or free will always take the same amount of time.
Constraints:
Function | Hwi | Swi | Task | Main | Startup |
---|---|---|---|---|---|
Params_init | Y | Y | Y | Y | Y |
alloc | Y | Y | Y | Y | N |
construct | Y | Y | Y | Y | N |
create | N* | N* | Y | Y | N |
delete | N* | N* | Y | Y | N |
destruct | Y | Y | Y | Y | N |
free | Y | Y | Y | Y | N |
getStats | Y | Y | Y | Y | N |
getExtendedStats | Y | Y | Y | Y | N |
isBlocking | Y | Y | Y | Y | N |
Definitions:
|
#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 | HeapBuf_ExtendedStats |
Stat structure for the HeapBuf_getExtendedStats function. More... | |
struct | HeapBuf_Params |
struct | HeapBuf_Struct |
Macros | |
#define | HeapBuf_A_nullBuf "buf parameter cannot be null" |
Null buf parameter. More... | |
#define | HeapBuf_A_bufAlign "buf not properly aligned" |
Misalligned buffer. More... | |
#define | HeapBuf_A_invalidAlign "align parameter must be 0 or a power of 2 >= the value of Memory_getMaxDefaultTypeAlign()" |
Invalid alignment. More... | |
#define | HeapBuf_A_invalidRequestedAlign "align parameter 1) must be 0 or a power of 2 and 2) not greater than the heaps alignment" |
Invalid alignment parameter in the alloc. More... | |
#define | HeapBuf_A_invalidBlockSize "blockSize must be large enough to hold at least two pointers" |
Assert raised when the blockSize parameter is not large enough to hold two pointers. More... | |
#define | HeapBuf_A_zeroBlocks "numBlocks cannot be zero" |
Assert raised when the numBlocks parameter is 0. More... | |
#define | HeapBuf_A_zeroBufSize "bufSize cannot be zero" |
Assert raised when the bufSize parameter is 0. More... | |
#define | HeapBuf_A_invalidBufSize "HeapBuf_create's bufSize parameter is invalid (too small)" |
Invalid buffer size. More... | |
#define | HeapBuf_A_noBlocksToFree "Cannot call HeapBuf_free when no blocks have been allocated" |
No allocated blocks. More... | |
#define | HeapBuf_A_invalidFree "Invalid free" |
Assert raised when an invalid free occurs. More... | |
#define | HeapBuf_E_size "requested size is too big: handle=0x%x, size=%u" |
Raised when requested size exceeds blockSize. More... | |
#define | ti_sysbios_heaps_HeapBuf_Handle_upCast(handle) ((IHeap_Handle)(handle)) |
cast handle to an IHeap_Handle for use by Memory_alloc, etc. More... | |
Typedefs | |
typedef struct HeapBuf_Struct * | HeapBuf_Handle |
typedef HeapBuf_Struct | HeapBuf_Object |
Functions | |
void * | HeapBuf_alloc (HeapBuf_Handle heap, size_t size, size_t align, Error_Block *eb) |
All alignment is handled in the create, therefore the align argument in alloc is ignored. More... | |
void | HeapBuf_free (HeapBuf_Handle heap, void *buf, size_t size) |
bool | HeapBuf_isBlocking (HeapBuf_Handle heap) |
This function always returns false since the alloc/free never block on a resource. More... | |
void | HeapBuf_getStats (HeapBuf_Handle heap, Memory_Stats *statBuf) |
This function returns state information for a HeapBuf. More... | |
void | HeapBuf_getExtendedStats (HeapBuf_Handle heap, HeapBuf_ExtendedStats *statBuf) |
Retrieves the extended statistics for a HeapBuf instance. More... | |
HeapBuf_Handle | HeapBuf_create (const HeapBuf_Params *params, Error_Block *eb) |
Create a HeapBuf heap. More... | |
HeapBuf_Handle | HeapBuf_construct (HeapBuf_Struct *obj, const HeapBuf_Params *params, Error_Block *eb) |
Construct a HeapBuf heap. More... | |
void | HeapBuf_delete (HeapBuf_Handle *heap) |
Delete a HeapBuf heap. More... | |
void | HeapBuf_destruct (HeapBuf_Struct *obj) |
Destruct a HeapBuf heap. More... | |
void | HeapBuf_Params_init (HeapBuf_Params *prms) |
Initialize the HeapBuf_Params structure with default values. More... | |
HeapBuf_Handle | HeapBuf_Object_first (void) |
return handle of the first HeapBuf on HeapBuf list More... | |
HeapBuf_Handle | HeapBuf_Object_next (HeapBuf_Handle heap) |
return handle of the next HeapBuf on HeapBuf list More... | |
#define HeapBuf_A_nullBuf "buf parameter cannot be null" |
Null buf parameter.
This Assert is raised when the buf parameter has been omitted (null) for a dynamic create.
#define HeapBuf_A_bufAlign "buf not properly aligned" |
Misalligned buffer.
This Assert is raised when the buf parameter has not been aligned on the requested alignment.
#define HeapBuf_A_invalidAlign "align parameter must be 0 or a power of 2 >= the value of Memory_getMaxDefaultTypeAlign()" |
Invalid alignment.
This Assert is raised when the align parameter is not the default value of zero, or a power of 2.
#define HeapBuf_A_invalidRequestedAlign "align parameter 1) must be 0 or a power of 2 and 2) not greater than the heaps alignment" |
Invalid alignment parameter in the alloc.
This Assert is raised when the align argument is not a power of 2 (or 0). It is also raised if the parameter is greater the alignment specified when creating the heap.
#define HeapBuf_A_invalidBlockSize "blockSize must be large enough to hold at least two pointers" |
Assert raised when the blockSize parameter is not large enough to hold two pointers.
#define HeapBuf_A_zeroBlocks "numBlocks cannot be zero" |
Assert raised when the numBlocks parameter is 0.
#define HeapBuf_A_zeroBufSize "bufSize cannot be zero" |
Assert raised when the bufSize parameter is 0.
#define HeapBuf_A_invalidBufSize "HeapBuf_create's bufSize parameter is invalid (too small)" |
Invalid buffer size.
This Assert is raised when the bufSize parameter is too small to handle requested blocks.
#define HeapBuf_A_noBlocksToFree "Cannot call HeapBuf_free when no blocks have been allocated" |
No allocated blocks.
This Assert is raised when free is called and there are no blocks allocated.
#define HeapBuf_A_invalidFree "Invalid free" |
Assert raised when an invalid free occurs.
This assert can be caused for the following reasons
#define HeapBuf_E_size "requested size is too big: handle=0x%x, size=%u" |
Raised when requested size exceeds blockSize.
#define ti_sysbios_heaps_HeapBuf_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 HeapBuf_Struct * HeapBuf_Handle |
typedef HeapBuf_Struct HeapBuf_Object |
void* HeapBuf_alloc | ( | HeapBuf_Handle | heap, |
size_t | size, | ||
size_t | align, | ||
Error_Block * | eb | ||
) |
All alignment is handled in the create, therefore the align argument in alloc is ignored.
HeapBuf_alloc will only fail if there are no available blocks or if the requested block size is larger than the HeapBuf's blockSize. All other requests, regardless of size, will succeed.
heap | heap handle |
size | size |
align | alignment |
eb | error block |
address | of allocated block (NULL on error) |
void HeapBuf_free | ( | HeapBuf_Handle | heap, |
void * | buf, | ||
size_t | size | ||
) |
bool HeapBuf_isBlocking | ( | HeapBuf_Handle | heap | ) |
This function always returns false since the alloc/free never block on a resource.
heap | heap handle |
always | returns false |
void HeapBuf_getStats | ( | HeapBuf_Handle | heap, |
Memory_Stats * | statBuf | ||
) |
This function returns state information for a HeapBuf.
heap | heap handle |
statBuf | pointer to stats object |
void HeapBuf_getExtendedStats | ( | HeapBuf_Handle | heap, |
HeapBuf_ExtendedStats * | statBuf | ||
) |
Retrieves the extended statistics for a HeapBuf instance.
This function retrieves the extended statistics for a HeapBuf instance. It does not retrieve the standard xdc.runtime.Memory.Stats information.
heap | heap handle |
statBuf | pointer to the extended stats structure. |
HeapBuf_Handle HeapBuf_create | ( | const HeapBuf_Params * | params, |
Error_Block * | eb | ||
) |
Create a HeapBuf
heap.
params | optional parameters |
eb | error block |
HeapBuf | handle (NULL on failure) |
HeapBuf_Handle HeapBuf_construct | ( | HeapBuf_Struct * | obj, |
const HeapBuf_Params * | params, | ||
Error_Block * | eb | ||
) |
Construct a HeapBuf
heap.
HeapBuf_construct is equivalent to HeapBuf_create except that the HeapBuf_Struct is pre-allocated.
obj | pointer to a HeapBuf object |
params | optional parameters |
eb | error block |
HeapBuf | handle (NULL on failure) |
void HeapBuf_delete | ( | HeapBuf_Handle * | heap | ) |
Delete a HeapBuf
heap.
Note that HeapBuf_delete takes a pointer to a HeapBuf_Handle which enables HeapBuf_delete to set the HeapBuf handle to NULL.
heap | pointer to a HeapBuf handle |
void HeapBuf_destruct | ( | HeapBuf_Struct * | obj | ) |
Destruct a HeapBuf
heap.
obj | pointer to a HeapBuf objects |
void HeapBuf_Params_init | ( | HeapBuf_Params * | prms | ) |
Initialize the HeapBuf_Params structure with default values.
HeapBuf_Params_init initializes the HeapBuf_Params structure with default values. HeapBuf_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 |
HeapBuf_Handle HeapBuf_Object_first | ( | void | ) |
return handle of the first HeapBuf on HeapBuf list
Return the handle of the first HeapBuf on the create/construct list. NULL if no HeapBufs have been created or constructed.
HeapBuf | handle |
HeapBuf_Handle HeapBuf_Object_next | ( | HeapBuf_Handle | heap | ) |
return handle of the next HeapBuf on HeapBuf list
Return the handle of the next HeapBuf on the create/construct list. NULL if no more HeapBufs are on the list.
heap | HeapBuf handle |
HeapBuf | handle |