OldSchool Library
Memory

Memory management routines. More...

Data Structures

struct  OSL_MEMSTATUS
 Structure for the return value of oslGetRamStatus. More...
 

Macros

#define oslUncacheData(data, size)
 Ensures that the data is no longer in the CPU cache.
 
#define oslGetUncachedPtr(adr)
 Returns a pointer to an uncached address.
 
#define oslGetCachedPtr(adr)
 Returns a pointer to cached data.
 

Functions

int sceDmacMemcpy (void *dest, const void *source, unsigned int size)
 Copies data using the internal DMAC.
 
int sceDmacTryMemcpy (void *dest, const void *source, unsigned int size)
 Same as sceDmacMemcpy.
 
void oslFasterMemset (u64 *dst, u64 *src, u32 length)
 Does a memset using the 64-bit capabilities of the CPU.
 
void oslFlushDataCache ()
 Flushes the whole cache.
 
void * memalign (size_t alignment, size_t size)
 Allocates a memory block, ensuring it is aligned.
 
OSL_MEMSTATUS oslGetRamStatus ()
 Gets info about currently available memory in main RAM.
 

Detailed Description

Memory management routines.

This section includes functions and macros for managing memory in OSLib, including cache management, memory copying, and alignment.

Macro Definition Documentation

◆ oslUncacheData

#define oslUncacheData ( data,
size )
Value:
sceKernelDcacheWritebackInvalidateRange(data, size);

Ensures that the data is no longer in the CPU cache.

This function flushes the cache, writing the data to the actual memory.

Parameters
dataAddress of the memory area to flush.
sizeSize (in bytes) of the area.

◆ oslGetUncachedPtr

#define oslGetUncachedPtr ( adr)
Value:
((void*)((int)(adr) | 0x40000000))

Returns a pointer to an uncached address.

This function allows you to bypass the cache, but it is generally less efficient than using cached addresses.

Parameters
adrCached address.
Returns
Uncached pointer.

◆ oslGetCachedPtr

#define oslGetCachedPtr ( adr)
Value:
((void*)((int)(adr) & (~0x40000000)))

Returns a pointer to cached data.

This function allows you to revert to using cached addresses.

Parameters
adrUncached address.
Returns
Cached pointer.

Function Documentation

◆ sceDmacMemcpy()

int sceDmacMemcpy ( void * dest,
const void * source,
unsigned int size )
extern

Copies data using the internal DMAC.

This function is generally faster than memcpy but requires that the data to be copied is no longer in the cache.

Parameters
destDestination address.
sourceSource address.
sizeSize of the data to be copied.
Returns
Result of the DMA copy operation.

◆ sceDmacTryMemcpy()

int sceDmacTryMemcpy ( void * dest,
const void * source,
unsigned int size )
extern

Same as sceDmacMemcpy.

This function is identical to sceDmacMemcpy but may be less reliable.

Parameters
destDestination address.
sourceSource address.
sizeSize of the data to be copied.
Returns
Result of the DMA copy operation.

◆ oslFasterMemset()

void oslFasterMemset ( u64 * dst,
u64 * src,
u32 length )
extern

Does a memset using the 64-bit capabilities of the CPU.

This function is faster than memcpy for certain operations.

Parameters
dstDestination address.
srcSource address.
lengthLength of the data to be set.

◆ oslFlushDataCache()

void oslFlushDataCache ( )
extern

Flushes the whole cache.

This function is slow and should be avoided if possible. Use oslUncacheData instead when appropriate.

◆ memalign()

void * memalign ( size_t alignment,
size_t size )

Allocates a memory block, ensuring it is aligned.

This function allocates memory with a specified alignment.

Parameters
alignmentAlignment in bytes.
sizeSize of the block.
Returns
Pointer to the allocated memory block.

◆ oslGetRamStatus()

OSL_MEMSTATUS oslGetRamStatus ( )

Gets info about currently available memory in main RAM.

This function returns an OSL_MEMSTATUS structure with information about the available memory.

Returns
OSL_MEMSTATUS structure containing available memory info.