To apply memory management to your application, the MemoryManager object needs to be specified in two
stages:
- At initialization phase. The purpose of specifying a MemoryManager object during initialization is to
create a separate memory manager for the overall application. Example of how this can be done is shown in
the example below
| | |
|
// Initialization step
static void XalanTransformer::initialize(MemoryManager* initMemoryManager=0);
| |
| | |
- Creation of a transformer instance. This creates a unique memory manager for the instance of the
processor. This step is optional. If no memory manager is provided, the global heap is used as the memory
source. Example of this is shown below:
| | |
|
// Create instance of XalanTransformer
MemoryManager memMgrA; // memory manager object
XalanTransformer transformerA(&memMgrA);
MemoryManager memMgrB;
XalanTransformer transformerB(&memMgrB);
XalanTransformer transformerC(&memMgrB); // Uses same memory manager object as transformerB
XalanTransformer transformerD; // Uses default static memory manager
| |
| | |
The above method demonstrates how users can apply the basic pluggable memory management feature. Users
also have the option of implementing their own memory manager. This can be done by simply writing methods
for:
| | |
|
// Method for allocating memory
void* allocate(size_t size);
| |
| | |
and
| | |
|
// Method for deallocating memory
void deallocate(void *p);
| |
| | |
For an example of how to use this feature, please see the
SimpleTransform sample that has been provided in the binary distributions.