flMemory.c File Reference

#include "flGlobal.h"
#include <malloc.h>
#include <stdio.h>
#include <string.h>
#include <pspkernel.h>

Go to the source code of this file.

Functions

void memInit ()
 Called by flInitialize() to initialize the memory system.
void memTerm ()
 Called by flTerminate() to deinitialize the memory system.
u32 memFreeSpace (u32 inAccuracy)
 Returns a close estimate of the amount of free space.
u32 memFreeSpaceTotal ()
 Returns a close estimate of the total amount of free space available to the program on the whole system, this includes video memory, scratchpad and any other memory funcLib can get it's hands on.
char * memString (u32 inBytes, bool inBinary)
 Converts an amount of bytes into a more humanly readable string to be printed in a log or to the screen.
void memSetByteFrom (void *inPtr, int inVal, unsigned int inSize, const char *inFile, const char *inFunc, int inLine)
void memSetShortFrom (void *inPtr, int inVal, unsigned int inSize, const char *inFile, const char *inFunc, int inLine)
void memClearFrom (void *inPtr, unsigned int inSize, const char *inFile, const char *inFunc, int inLine)
void memCopyFrom (void *inDest, void *inSrc, unsigned int inSize, const char *inFile, const char *inFunc, int inLine)
int memCompareFrom (void *inSrc0, void *inSrc1, unsigned int inSize, const char *inFile, const char *inFunc, int inLine)
void * memAllocFrom (int inSize, const char *inFile, const char *inFunc, int inLine)
 This functions is identical to memAlloc() except that it takes extra parameters to define where it was called from,.
void * memQallocFrom (int inSize, const char *inFile, const char *inFunc, int inLine)
void * memCallocFrom (int inSize0, int inSize1, const char *inFile, const char *inFunc, int inLine)
void * memAllocUncachedFrom (int inSize, const char *inFile, const char *inFunc, int inLine)
void * memReallocFrom (void *inData, int inSize, const char *inFile, const char *inFunc, int inLine)
void * memAlignFrom (int inBoundry, int inSize, const char *inFile, const char *inFunc, int inLine)
void memFreeFrom (void *inData, const char *inFile, const char *inFunc, int inLine)
void * memUncachedPtrFrom (void *inPtr, const char *inFile, const char *inFunc, int inLine)
u32 memAddressAlignment (void *inPtr)
 Calculates the largest binary increment that a pointer is aligned to (e.g 16, 32, 64, 128, etc.
bool memAddressValid (void *inPtr)
 Checks if a pointer resides within valid memory blocks on the terget platform.
bool memBlockValid (void *inPtr, u32 inSize)
 Checks if a memory block resides within valid memory blocks on the terget platform.
bool memErrorBytesCheckFrom (void *inPtr, const char *inFile, const char *inFunc, int inLine)
void memtAddFrom (MemoryTree **inMemTree, void *inPtr, u32 inSize, u32 inAlignment, const char *inFile, const char *inFunc, int inLine)
void memtDelFrom (MemoryTree **inMemTree, void *inPtr, const char *inFile, const char *inFunc, int inLine)
void memtErrorBytesCheckFrom (MemoryTree **inMemTree, const char *inFile, const char *inFunc, int inLine)

Variables

MemoryTreememErrorTree = NULL
bool memInitialized = false
 A boolean to represent whether the memory system has been initialized or not, this is set by memInit() and memTerm().
bool memScratchpadUsed = false
 A boolean to represent whether the scratchpad is currently in use or not, this allows the fastest possible allocation/free'ing of memory for temp data.


Function Documentation

u32 memAddressAlignment ( void *  inPtr  ) 

Calculates the largest binary increment that a pointer is aligned to (e.g 16, 32, 64, 128, etc.

).

Parameters:
inPtr The pointer whose alignment will be calculated.
Returns:
The mamximum alignment value.

Definition at line 912 of file flMemory.c.

Referenced by vmemStrideBlockAdd().

bool memAddressValid ( void *  inPtr  ) 

Checks if a pointer resides within valid memory blocks on the terget platform.

Parameters:
inPtr The pointer whose validity will be checked.
Returns:
True if the pointer is valid.

Definition at line 922 of file flMemory.c.

References memCachedPtr, MEMORY_SCRATCHPAD_BASE, MEMORY_SCRATCHPAD_SIZE, MEMORY_USER_BASE, MEMORY_USER_SIZE, MEMORY_VMEM_BASE, and MEMORY_VMEM_SIZE.

Referenced by memFreeFrom().

void* memAlignFrom ( int  inBoundry,
int  inSize,
const char *  inFile,
const char *  inFunc,
int  inLine 
)

Definition at line 702 of file flMemory.c.

References debugWarning, debugWarningFrom(), FL_MEMORY_ALIGNMENT_DEFAULT, memAlign, memErrorTree, MEMORY_SCRATCHPAD_BASE, memScratchpadUsed, memtAdd, memtAddFrom(), memtErrorBytesCheck, memtErrorBytesCheckFrom(), NULL, vmemAlloc, and vmemStrideAlign().

Referenced by memAllocFrom().

void* memAllocFrom ( int  inSize,
const char *  inFile,
const char *  inFunc,
int  inLine 
)

This functions is identical to memAlloc() except that it takes extra parameters to define where it was called from,.

Parameters:
inSize The size of the block to be allocated.
inFile The source file that the original call came from.
inFunc The function that the original call originated from.
inLine The line on which the original call was on.
Returns:
A pointer to the allocated memory block.
See also:
memAlloc(), memAlloc

Definition at line 511 of file flMemory.c.

References FL_MEMORY_ALIGNMENT_DEFAULT, and memAlignFrom().

Referenced by memCallocFrom().

void* memAllocUncachedFrom ( int  inSize,
const char *  inFile,
const char *  inFunc,
int  inLine 
)

Definition at line 577 of file flMemory.c.

References debugWarning, debugWarningFrom(), FL_MEMORY_ALIGNMENT_DEFAULT, max, memAlign, memAllocUncached, memUncachedPtr, and NULL.

bool memBlockValid ( void *  inPtr,
u32  inSize 
)

Checks if a memory block resides within valid memory blocks on the terget platform.

Parameters:
inPtr The pointer to the start of the memory block whose validity will be checked.
inSize The length of the memory block whose validity will be checked.
Returns:
True if the pointer is valid.

Definition at line 933 of file flMemory.c.

References memCachedPtr, MEMORY_SCRATCHPAD_BASE, MEMORY_SCRATCHPAD_SIZE, MEMORY_USER_BASE, MEMORY_USER_SIZE, MEMORY_VMEM_BASE, and MEMORY_VMEM_SIZE.

Referenced by memClearFrom(), memCompareFrom(), memCopyFrom(), memSetByteFrom(), memSetShortFrom(), memtAddFrom(), memtErrorBytesCheckFrom(), and vmemStrideBlockAdd().

void* memCallocFrom ( int  inSize0,
int  inSize1,
const char *  inFile,
const char *  inFunc,
int  inLine 
)

Definition at line 560 of file flMemory.c.

References memAlloc, memAllocFrom(), memCalloc, memClear, memClearFrom(), and NULL.

void memClearFrom ( void *  inPtr,
unsigned int  inSize,
const char *  inFile,
const char *  inFunc,
int  inLine 
)

Definition at line 307 of file flMemory.c.

References debugWarning, debugWarningFrom(), memBlockValid(), memClear, memErrorTree, memtErrorBytesCheck, and memtErrorBytesCheckFrom().

Referenced by memCallocFrom().

int memCompareFrom ( void *  inSrc0,
void *  inSrc1,
unsigned int  inSize,
const char *  inFile,
const char *  inFunc,
int  inLine 
)

Definition at line 453 of file flMemory.c.

References debugWarning, debugWarningFrom(), memBlockValid(), memCompare, memErrorTree, memtErrorBytesCheck, and memtErrorBytesCheckFrom().

void memCopyFrom ( void *  inDest,
void *  inSrc,
unsigned int  inSize,
const char *  inFile,
const char *  inFunc,
int  inLine 
)

Definition at line 366 of file flMemory.c.

References debugWarning, debugWarningFrom(), memBlockValid(), memCopy, memErrorTree, memFree, memQalloc, memtErrorBytesCheck, and memtErrorBytesCheckFrom().

bool memErrorBytesCheckFrom ( void *  inPtr,
const char *  inFile,
const char *  inFunc,
int  inLine 
)

Definition at line 1039 of file flMemory.c.

References debugError, debugErrorFrom(), and memErrorBytesCheck.

void memFreeFrom ( void *  inData,
const char *  inFile,
const char *  inFunc,
int  inLine 
)

Definition at line 820 of file flMemory.c.

References debugError, debugErrorFrom(), debugWarning, debugWarningFrom(), memAddressValid(), memErrorBytesCheck, memErrorTree, memFree, MEMORY_SCRATCHPAD_BASE, MEMORY_SCRATCHPAD_SIZE, memScratchpadUsed, memtDel, memtDelFrom(), memtErrorBytesCheck, memtErrorBytesCheckFrom(), vmemFree, vmemFreeFrom(), and vmemPointer.

u32 memFreeSpace ( u32  inAccuracy  ) 

Returns a close estimate of the amount of free space.

Parameters:
inAccuracy The amount of bytes that the returned answer should be accurate to.
Returns:
The amount of free space accurate to inAccuracy bytes.
Note:
Since malloc allocates 16 byte aligned data, this is the closest accuracy you will get, so there's not much point in setting inAccuracy to below 16.

Definition at line 101 of file flMemory.c.

References MEMORY_USER_SIZE.

Referenced by memFreeSpaceTotal().

u32 memFreeSpaceTotal (  ) 

Returns a close estimate of the total amount of free space available to the program on the whole system, this includes video memory, scratchpad and any other memory funcLib can get it's hands on.

Returns:
The amount of free space available on the whole system, to the highest accuracy possible.

Definition at line 128 of file flMemory.c.

References memFreeSpace(), memScratchpadUsed, and vmemFreeSpace().

void memInit (  ) 

Called by flInitialize() to initialize the memory system.

See also:
flInitialize(), memTerm()

Definition at line 28 of file flMemory.c.

References debugError, debugStatusLog, FL_DEBUG_STATUS, memCopy, memInitialized, MEMORY_SCRATCHPAD_BASE, and MEMORY_SCRATCHPAD_SIZE.

Referenced by flInitialize().

void* memQallocFrom ( int  inSize,
const char *  inFile,
const char *  inFunc,
int  inLine 
)

Definition at line 521 of file flMemory.c.

References debugWarningFrom(), memAlloc, memInitialized, MEMORY_SCRATCHPAD_BASE, MEMORY_SCRATCHPAD_SIZE, memQalloc, memScratchpadUsed, vmemAlloc, and vmemInitialized.

void* memReallocFrom ( void *  inData,
int  inSize,
const char *  inFile,
const char *  inFunc,
int  inLine 
)

Definition at line 608 of file flMemory.c.

References debugError, debugErrorFrom(), debugWarning, debugWarningFrom(), memErrorBytesCheck, memErrorTree, MEMORY_UNCACHED_OFFSET, memRealloc, memtAdd, memtAddFrom(), memtErrorBytesCheck, memtErrorBytesCheckFrom(), memUncachedPtr, NULL, vmemPointer, and vmemRealloc.

void memSetByteFrom ( void *  inPtr,
int  inVal,
unsigned int  inSize,
const char *  inFile,
const char *  inFunc,
int  inLine 
)

Definition at line 175 of file flMemory.c.

References debugWarning, debugWarningFrom(), memBlockValid(), memErrorTree, memSetByte, memtErrorBytesCheck, and memtErrorBytesCheckFrom().

void memSetShortFrom ( void *  inPtr,
int  inVal,
unsigned int  inSize,
const char *  inFile,
const char *  inFunc,
int  inLine 
)

Definition at line 240 of file flMemory.c.

References debugWarning, debugWarningFrom(), memBlockValid(), memErrorTree, memSetShort, memtErrorBytesCheck, and memtErrorBytesCheckFrom().

char* memString ( u32  inBytes,
bool  inBinary 
)

Converts an amount of bytes into a more humanly readable string to be printed in a log or to the screen.

Parameters:
inBytes The amount of bytes.
inBinary If set to true then it will return binary results where there are 1024 bytes in a Kilobyte (and append e.g. "KiB"), if not then a KiloByte will be considered 1000 bytes (and e.g "KB" will be printed).
Returns:
A string representing the bytes in SI units, (e.g 1024 bytes = "1 KiB" or "1.02 KB").
Warning:
This returns an allocated string that must be free'd after use.
See also:
memFreeSpace(), memFreeSpaceTotal(), memFree()

Definition at line 137 of file flMemory.c.

References memAlloc.

void memtAddFrom ( MemoryTree **  inMemTree,
void *  inPtr,
u32  inSize,
u32  inAlignment,
const char *  inFile,
const char *  inFunc,
int  inLine 
)

Definition at line 1083 of file flMemory.c.

References debugError, debugErrorFrom(), memBlockValid(), memtAdd, MemoryTree::memtAlignment, MemoryTree::memtData, MemoryTree::memtNext, MemoryTree::memtSize, and NULL.

Referenced by memAlignFrom(), and memReallocFrom().

void memtDelFrom ( MemoryTree **  inMemTree,
void *  inPtr,
const char *  inFile,
const char *  inFunc,
int  inLine 
)

Definition at line 1151 of file flMemory.c.

References debugError, debugErrorFrom(), flRunning, MemoryTree::memtData, memtDel, MemoryTree::memtNext, and NULL.

Referenced by memFreeFrom().

void memTerm (  ) 

Called by flTerminate() to deinitialize the memory system.

See also:
flTerminate(), memInit()

Definition at line 72 of file flMemory.c.

References debugStatusLog, fileDelete(), FL_MEMORY_PAGE_PATH, memClear, memCopy, memInitialized, MEMORY_SCRATCHPAD_BASE, and MEMORY_SCRATCHPAD_SIZE.

Referenced by flTerminate().

void memtErrorBytesCheckFrom ( MemoryTree **  inMemTree,
const char *  inFile,
const char *  inFunc,
int  inLine 
)

Definition at line 1196 of file flMemory.c.

References debugError, debugErrorFrom(), debugWarning, debugWarningFrom(), FL_DEBUG_CALLEDFROM, FL_DEBUG_ERROR, memBlockValid(), MemoryTree::memtAlignment, MemoryTree::memtData, memtErrorBytesCheck, MemoryTree::memtNext, and MemoryTree::memtSize.

Referenced by memAlignFrom(), memClearFrom(), memCompareFrom(), memCopyFrom(), memFreeFrom(), memReallocFrom(), memSetByteFrom(), and memSetShortFrom().

void* memUncachedPtrFrom ( void *  inPtr,
const char *  inFile,
const char *  inFunc,
int  inLine 
)

Definition at line 894 of file flMemory.c.

References debugWarning, debugWarningFrom(), MEMORY_UNCACHED_OFFSET, memUncachedPtr, and NULL.


Variable Documentation

MemoryTree* memErrorTree = NULL

Definition at line 22 of file flMemory.c.

Referenced by memAlignFrom(), memClearFrom(), memCompareFrom(), memCopyFrom(), memFreeFrom(), memReallocFrom(), memSetByteFrom(), and memSetShortFrom().

bool memInitialized = false

A boolean to represent whether the memory system has been initialized or not, this is set by memInit() and memTerm().

See also:
memInit(), memTerm()

Definition at line 25 of file flMemory.c.

Referenced by memInit(), memQallocFrom(), and memTerm().

bool memScratchpadUsed = false

A boolean to represent whether the scratchpad is currently in use or not, this allows the fastest possible allocation/free'ing of memory for temp data.

See also:
memQalloc()

Definition at line 26 of file flMemory.c.

Referenced by memAlignFrom(), memFreeFrom(), memFreeSpaceTotal(), and memQallocFrom().


Generated on Wed Sep 5 19:04:02 2007 for funcLib by  doxygen 1.5.1