Some of the NintendoWare libraries perform necessary memory allocation for themselves. While these libraries require the dynamic allocation of memory within the library, any method of memory resource management can be used. It's therefore preferable to avoid any dependence on a particular memory management library.
A memory allocator mechanism has therefore been introduced to address this. The memory allocator is used in conjunction with a specific memory management library. The memory allocator provides only the functionality for allocating and freeing memory while the actual operations are carried out by calling the memory management library functionality. The library receives the memory allocator, and allocates and deallocates memory through the allocator. Therefore, the library is not dependent on a specific memory management library.
Before using a memory allocator, it must be initialized. The memory allocator holds the required information in a structure named MEMAllocator, and is initialized by passing the pointer to this structure in the initialization function. There are four types of initialization functions, and they correspond to the three MEM library heaps and one RevolutionSDK OS heap. The initialization functions are described below.
| Functions | Features |
| MEMInitAllocatorForExpHeap | Initializes the allocator to allocate and free memory from the expanded heap. |
|---|---|
| MEMInitAllocatorForFrmHeap | Initializes the allocator to allocate and deallocate memory from the frame heap. |
| MEMInitAllocatorForUnitHeap | Initializes the allocator to allocate and deallocate memory from the unit heap. |
| MEMInitAllocatorForOSHeap | Initializes the allocator to allocate and deallocate memory from the RevolutionSDK OS heap. |
Regardless of which initialization function is used, the corresponding heap must be created before the function is called.
There are two memory allocator functions; one for allocating and one for deallocating memory. The actual behavior depends on the type of the memory management library associated with the function. The functions for allocating and deallocating memory blocks are described in the table below.
| Functions | Features |
| MEMAllocFromAllocator | Allocates memory blocks from the allocator. |
|---|---|
| MEMFreeToAllocator | Returns the memory block to the allocator and frees the memory block. |
Situations may arise where you want to use a unique memory management library with a memory allocator, or to change the behavior of a conventionally prepared memory allocator. You can do so by uniquely implementing the memory allocator. Refer to the memory allocator source for instructions on unique implementation.
2006/03/01 Initial version.
CONFIDENTIAL