Using the Region Allocation Routines

Previous examples were primarily concerned with static memory allocation; many applications may find it necessary to do some form of dynamic allocation. For situations where the allocation is always done in fixed size chunks, a family of region allocation routines are provided. These routines will carve up a larger buffer into fixed some memory regions that are managed by the library. The routines of interest are:

The following code sample creates a region, allocates a buffer, and then frees it.

void *region;
        char regionMemory[REGION_SIZE];
        u64 *buffer;

        region = osCreateRegion(regionMemory,
                               sizeof(regionMemory),
                               BUFFER_SIZE, OS_RG_ALIGN_16B);
        buffer = osMalloc(region);
 
        /* do some work that uses ‘buffer’ */

        osFree(region, buffer);

Incidentally, if the fixed size regions are intended to hold entire segments, the maxsize keyword of the makerom specification file may be of interest. See makerom(1P) for details.

Copyright © 1999
Nintendo of America Inc. All Rights Reserved
Nintendo and N64 are registered trademarks of Nintendo
Last Updated January, 1999