Memory Management Functions
Memory management functions handle the allocation and deallocation of dynamic memory. These functions form an abstraction layer above the standard C memory management functions malloc, free, and realloc. This block of functions can be replaced by the user with custom code to implement a different memory management scheme. For example, an embedded system application might want to use a fixed-sized static block from which to allocate.
The built-in memory management logic implements a nibble-allocation memory management algorithm that provides superior performance to calling malloc and free directly. This algorithm causes memory blocks to be allocated up front in larger sizes and then subsequently split up when future allocation requests are received. These blocks can be reset and reused in applications that are constantly allocating and freeing memory (for example, a decoder that constantly reads and decodes XML messages in a long running loop).
- rtxMemAlloc - This function allocates a block of memory in much the same way malloc would. The only difference from the user's perspective is that a pointer to a context structure is required as an argument. The allocated memory is tracked within this context.
- rtxMemFreePtr - This function releases the memory held by a pointer in much the same way the C free function would. The only difference from a user's perspective is that a pointer to a context structure is required as an argument. This context must have been used in the call to rtxMemAlloc at the time the memory was allocated.
- rtxMemFree - This function releases all memory held within a context.
- rtxMemReset - This functions resets all memory held within a context. The difference between this and the rtxMemFree function is that this function does not actually free the blocks that were previously allocated. It only resets the pointers and indexes within those blocks to allow the memory to be reused.
- rtxMemRealloc - This function works in the same way as the C realloc function. It reallocates an existing block of memory. As in the other cases above, a pointer to a context structure is a required argument.
Copyright © Objective Systems 2002-2008 This document may be distributed in any form, electronic or otherwise, provided that it is distributed in its entirety and that the copyright and this notice are included. |
Objective Systems, Inc.55 Dowlin Forge RoadExton, Pennsylvania 19341 http://www.obj-sys.com Phone: (484) 875-9841 Toll-free: (877) 307-6855 (US only) Fax: (484) 875-9830 info@obj-sys.com |