The Default Heap

The default heap is used for generic allocations. It is set up by the C runtime library for Cafe before the main entry point for your application and before the constructors of global C++ objects.

This means that if you use memory in a constructor for a global object, the allocations are from the default heap.

The default heap may be changed at runtime, and may even be supplanted or overridden during the initialization of your application.

Default Heap is the Base Heap for MEM2

There is more than one type of memory on the Cafe. The memory types are distinguished as different Arenas. For example, the MEM1 Arena is fast, secure, but small. The MEM2 Arena is large, but is slower than MEM1 and is not secure.

Each memory arena (MEM1, MEM2) has a heap associated with it. These heaps are known as the base heap of the arena. For more information on the base heaps, see Base Heap. The default type of heap for the MEM1 base heap is a Frame heap. The default type of heap for the MEM2 base heap is an Expanded heap.

The base heap for MEM2 is also known as the default heap.

Creating new heaps is performed as a sub-allocation of a contiguous range from a base heap, or a heap that traces its ancestry to a base heap.

Using Memory

Cafe uses C and C++ as a language for development. In C, you may allocate and free memory using the standard C functions that are dedicated for that purpose:

void * malloc(size_t bytes);

void   free(void *ptr);

In C++ you may use either the C interface functions, or the new and delete operators:

void * ::operator new(size_t bytes);

void   ::operator delete(void *ptr);

In Cafe, either of these methods use whatever heap is set as the default heap. Let’s consider what happens in the general case by looking at the implementations of the standard C functions (the C++ functions are analogous).

void * malloc(size_t size)
{
    return MEMAllocFromDefaultHeap(size);
}
void free(void *ptr)
{
    MEMFreeToDefaultHeap(ptr);
}

These simple functions are called wrappers, because they allow a large amount of portable C code that use malloc and free to work seamlessly with Cafe. If you are trying to write portable code that works with other systems or may work with other allocating schemes in the future, it is recommended that you use the standard C malloc and free, and not use the MEM functions directly.

If you do not need to allocate memory in a special way or from a particular place, these functions are all that you need to be concerned with. If you want to create and use your own heaps for your own purposes, you may do so by allocating memory for them from another heap that you created, or from the base heap for an Arena.

Default Heap Memory Usage by Various API Functions

AX API Functions

Default heap memory usage for AXFX effects varies depending on the effect and the sample frequency of audio renderer. The table below lists AXFX effects and the default heap memory used in sound-1 and sound-2.

AX Effects Memory Usage
Effect Bytes (/KB)
sound-1 sound-2
32KHz 32KHz 48KHz
Chorus 2ch 25 25 37
Chorus 4ch 51 50 75
Chorus 6ch 77 63 94
Compressor 2ch N/A 0.1 0.1
Compressor 4ch N/A 0.1 0.1
Compressor 6ch N/A 0.1 0.1
Delay 2ch 512 [26 ~ 256] [39 ~ 384]
Delay 4ch 1024 [52 ~ 512] [78 ~ 768]
Delay 6ch 1536 [78 ~ 768] [117 ~ 1152]
Flanger 2ch N/A 4 6
Flanger 4ch N/A 7 11
Flanger 6ch N/A 9 14
Overdrive 2ch N/A 0.1 0.1
Overdrive 4ch N/A 0.1 0.1
Overdrive 6ch N/A 0.1 0.1
PitchShift 2Ch N/A 13 19
PitchShift 4Ch N/A 26 39
PitchShift 6Ch N/A 39 57
Reverb 2ch 98 79 118
Reverb 4ch 136 79 118
Reverb 6ch 137 79 119
ReverbI3dl2 2ch N/A 134 200
ReverbI3dl2 4ch N/A 134 200
ReverbI3dl2 6ch N/A 135 201

Networking API Functions

Libcurl

Libcurl default memory usage varies, depending on the following criteria:

Requests

A maximum of 6144 bytes per request, or up to 190,464 bytes total.

GX2 API Functions

Camera API Functions

NONE

USB_MIC API Functions

USB microphones do not exceed 100 KB per device, or 200 KB total.

ProcUI API Functions

Each ProcUI callback uses 112 bytes. As long as the size of OSAlarm and OSTime do not change, this should not change.

Revision History

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


CONFIDENTIAL