-
Notifications
You must be signed in to change notification settings - Fork 0
heap manager examples
At first, memory pool must be declared, for example (all heap stuff placed in namespace heap):
#include <stdint.h>
#include <heap.h>
heap::pool<4096> HeapPool; // size in bytesHeap pool may have any language-supported name.
Another example - placing heap pool in separate memory section:
__attribute__((section(".heap")))
heap::pool<4096> HeapPool; // size in bytesHeap configuration file heapcfg.h must be created and added to the user project. See thread-safe guard page for more details.
Heap manager can be declared in any user's source file as template-class object with HeapPool argument:
heap::manager<heap_guard> heap::Manager(HeapPool);Internally, heap pool is an array of int type. This comes from alignment requirements on target platform. The user can declare heap pool in C-language manner, for example:
int HeapPool[ 4096/sizeof(int) ];In this case heap manager declaration looks like:
heap::manager<heap_guard> heap::Manager(HeapPool, sizeof(HeapPool));Or if memory pool object declared in the same scope (i.e. type and size of the object are known), there is more short alternative:
heap::manager<heap_guard> heap::manager(HeapPool);Or memory pool can be declared as properly aligned external raw memory array:
extern void * const Heap_pool_start;
extern size_t const Heap_pool_size;
heap::manager<heap_guard> heap::manager(Heap_pool_start, Heap_pool_size);The recommended approach is to use heap::pool<> because it is less error-prone.
Note, that object name heap::Manager and template parameter name heap_guard are predefined and cannot be changed by user.