Memory Allocator

Introduction

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 is preferable to avoid any dependence on a particular memory management library.

A memory allocator mechanism has 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. The library is not dependent on a specific memory management library.

Initializing Memory Allocators

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 Cafe SDK OS heap. The initialization functions are described below.

Functions for Initializing the Memory Allocator
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.

Regardless of which initialization function is used, the corresponding heap must be created before the function is called.

Memory Allocator Functions

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 for Allocating and Freeing Memory Blocks
Functions Features
MEMAllocFromAllocator Allocates memory blocks from the allocator.
MEMFreeToAllocator Returns the memory block to the allocator and frees the memory block.

Associating Unique Memory Management Libraries and Memory Allocators

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. Do so by uniquely implementing the memory allocator. Refer to the memory allocator source for instructions on unique implementation.

Revision History

2013/05/08 Automated cleanup pass.
2010/11/01 Initial version.


CONFIDENTIAL