Memory Management Functions

The XBinder runtime provides a high level memory management API to 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 implementation of the high level memory management API 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).

The nibble-allocation memory management can be tuned by setting the default memory heap block size. The way memory management works is that a large block of memory is allocated up front on the first memory management call. This block is then subdivided on subsequent calls until the memory is used up. A new block is then started. The default value is 4K (4096) bytes. The value can be set lower for space constrained systems and higher to improve performance in systems that have sufficient memory resources. To set the block size, the following run-time function should be used:

   void rtxMemSetDefBlkSize (OSUINT32 blkSize);

This function must be called prior to context initialization.