#include <cafe/mem.h>

void* MEMAllocFromExpHeapEx(
                    MEMHeapHandle    heap,
                    u32              size,
                    int              alignment );


heap Expanded heap handle.
size Size of the memory block in bytes.
alignment Memory block alignment. The following values can be specified: 4, 8, 16, 32, 64, 128, ..., 128KB, -4, -8, -16, -32, -64, -128, ..., -128KB.

Return Values

When the memory block is allocated, the start address of this memory block is returned. When memory cannot be allocated, NULL is returned.


Allocates a memory block from the expanded heap. Memory block alignment is specified by alignment. If the alignment is a negative value, the memory block is allocated from the top of the free region in the heap.

The gap in memory caused by alignment is set by default to not be reused.
Use the MEMUseMarginOfAlignmentForExpHeap function to change this setting so that this alignment gap, or margin, can be reused as a free memory region. However, note that performance may be adversely affected if you specify an alignment value of 32 or more or –32 or less when you allocate memory because small free blocks will be registered whenever small gaps arise between memory blocks.

If the memory block is allocatable, the actual size of the memory block may be greater than the specified size. To determine the actual allocated size in bytes, use the MEMGetSizeForMBlockExpHeap function.

Do Not Call From

Callbacks Do not call this function from any callback function.

See Also


Revision History

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