LCAlloc

Syntax

#include <cafe/os.h>
    
void* LCAlloc( u32 nBytes );

Parameters

nBytes The number of bytes to allocate from the locked cache. The minimum size is 512 bytes (LC_MIN_ALLOC) and must be a multiple of 512 bytes.

Return Values

Returns NULL on failure. Returns the pointer to locked cache memory on success.

Description

Allocates locked cache memory from the current core. Each core has its own locked cache memory heap.

With dynamic allocation and deallocation, fragmentation can occur where the desired number of bytes is unallocated but not contiguous. The heap algorithm first tries to allocate the memory on addresses aligned based on size. For example, a 1024B allocation request tries to find a free 1024B block on a 1024-byte aligned address. If none is found, then a first-fit search starting at the low LC address is used.

An application can allocate a maximum of 16 KB for each core. If there is LC space left unused (2 to 4 KB), the system libraries and operating system can take advantage of it and potentially increase performance (such as for C libraries).

NOTE:
Locked-cache is always available to the main application (e.g. game) on Core 2 without regard to a foreground or background state.
Locked-cache is available on Core 0 and Core 1 only when the application is in the foreground state.

Do Not Call From

Background, Cores 0 & 1 In applications, do not call this function from Core 0 or 1 when in the background.
Callbacks Do not call this function from any callback function.

See Also

LCDealloc
LCDisableDMA
LCEnableDMA
LCGetAllocatableSize
LCGetDMAQueueLength
LCGetMaxSize
LCGetUnallocated
LCHardwareIsAvailable
LCIsDMAEnabled
LCLoadDMABlocks
LCStoreDMABlocks
LCWaitDMAQueue

Revision History

2013/05/08 Automated cleanup pass.
2012/05/08 Updated LCAlloc and LCDealloc. Added LCGetAllocatableSize. Removed LCLoadDMAASync and LCStoreDMAASync.
2012/05/08 Added LCHardwareIsAvailable.
2011/03/15 Initial version.


CONFIDENTIAL