Another alternative memory management capability is static block memory management. This is a faster alternative to the nibble-allocation scheme but one that comes with some limitations. The main limitations are:
The capability to free an individual memory pointer (rtxMemFreePtr) is not available. The block must be freed as a whole
The capability to reallocate memory (rtxMemRealloc) is not available.
The user must estimate up front what the maximum size of all allocations will be as once all memory in the block is exhausted, further allocation attempts will fail.
Despite these limitations, this type of memory management may be a good choice for simple, memory-based decoding because a decoder normally does not require free and reallocation capabilities. It simply progresses sequentially through a message and allocates memory for decoded items. If decoding in a loop, the rtxMemReset function can be used to free the entries block up for storage for items in the next message.
To use the capability, a user would release the memory heap created
in the context structure after initialization with the static block
they wanted to use using the rtxMemStaticHeapCreate
function
as follows:
/* Set static memory heap */ rtxMemHeapRelease (&ctxt.pMemHeap); rtxMemStaticHeapCreate (&ctxt.pMemHeap, staticMemHeap, sizeof(staticMemHeap));
The staticMemHeap
variable would simply be a byte array of
the desired size. It also could be a block of memory allocated using
malloc
or new
.