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 divide up a larger buffer into some fixed 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 for details.