The SGADE Documentation

the SGADE The Socrates Gameboy Advance Development Engine

The SGADE is a development library for the Nintendo Gameboy Advance. It's free for all uses and is distributed without guarantees. For more information visit the SGADE page.


Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages  

SoMemManager.c File Reference

#include "SoMemManager.h"
#include "SoDebug.h"

Data Structures

struct  SoMemManagerHdr_t
 memory manager header More...

struct  SoMemManagerNode_t
 Free pool tree node. More...


Defines

#define SO_MEM_MANAGER_NULL_IDX
 NULL node index ('pointer') value.

#define SoMemManagerHdr()
#define SoMemManagerPoolArg()
#define SoMemManagerAddx(iBlock)
#define BITSPERBYTE
 The number of bits in a byte.


Functions

void SoMemManagerInsertNode (u32 *pMemPool, u16 iParentNode, struct SoMemManagerNode_t *pParentNode, u16 iInsNode)
 insert new node into (subtree of) free node tree

void SoMemManagerRemoveNode (u32 *pMemPool, u16 iNode, struct SoMemManagerNode_t *pNode)
 Remove specified node from free pool tree.

bool SoMemManagerBitCheck (u8 *bmdata, u16 bitnum)
 tests to see if bit in bitmap is set

void SoMemManagerBitSet (u8 *bmdata, u16 bitnum)
 sets a bit in a bitmap

void SoMemManagerBitClear (u8 *bmdata, u16 bitnum)
 clears a bit in a bitmap

bool IsFirstBlock (u32 *pMemPool, u16 iBlock)
 tests to see if this is the first block in an free range

bool IsUsedBlock (u32 *pMemPool, u16 iBlock)
 tests to see if the block is allocated

void SetBlockMemMap (u32 *pMemPool, u16 iBlock, u16 iSize, bool bOnOff)
 sets an allocation range to used/free

void SoMemManagerInit (u32 *pMemPool, u32 iBufSize, u16 iBlockSize)
 initialize memory pool for allocation

void * SoMemManagerAlloc (u32 *pMemPool, u16 iSize)
 Allocate memory from free pool.

void SoMemManagerFree (void *pMemPool, void *pBuf)
 Release memory back to free pool.


Detailed Description

Copyright (C) 2002 by the SGADE authors For conditions of distribution and use, see copyright notice in SoLicense.txt

Author:
Mark T. Price
Date:
Aug 9 2001
See the SoMemManager module for more information.


Define Documentation

#define BITSPERBYTE
 

The number of bits in a byte.

For internal use only.

#define SO_MEM_MANAGER_NULL_IDX
 

NULL node index ('pointer') value.

For internal use only.

#define SoMemManagerAddx iBlock   
 

For internal use only.

 
#define SoMemManagerHdr  
 

For internal use only.

 
#define SoMemManagerPoolArg  
 

For internal use only.


Function Documentation

bool IsFirstBlock u32   pMemPool,
u16    iBlock
[static]
 

tests to see if this is the first block in an free range

Parameters:
pMemPool  the memory pool (this argument is omitted if SO_MEM_MANAGER_SINGLE_POOL_BASE is define'd)
iBlock  index of block to test

For internal use only.

bool IsUsedBlock u32   pMemPool,
u16    iBlock
[static]
 

tests to see if the block is allocated

Parameters:
pMemPool  the memory pool (this argument is omitted if SO_MEM_MANAGER_SINGLE_POOL_BASE is define'd)
iBlock  index of block to test

For internal use only.

void SetBlockMemMap u32   pMemPool,
u16    iBlock,
u16    iSize,
bool    bOnOff
 

sets an allocation range to used/free

Parameters:
pMemPool  the memory pool (this argument is omitted if SO_MEM_MANAGER_SINGLE_POOL_BASE is define'd)
iBlock  block index of start of range
iSize  number of blocks in range
bOnOff  state to set (true=used, false=free)

For internal use only.

void* SoMemManagerAlloc u32   pMemPool,
u16    iSize
 

Allocate memory from free pool.

Parameters:
pMemPool  The starting address of the free pool. Must have been previously initialized by calling SoMemManagerInit (this argument is omitted if SO_MEM_MANAGER_SINGLE_POOL_BASE is define'd)
iSize  The number of bytes to be allocated
Returns :
pointer to allocated buffer, or NULL if none was available
Always make sure that you test for the failure case. If you always consider allocation failure to be fatal you can just uncomment SO_MEM_MANAGER_ASSERT_FAILURE in the SoMemManager.h file and this function will call SO_ASSERT on failure. You may want to consider doing this in your code, however, as you will then know what call caused the problem.

The memory allocated by this function is not zeroed or initialized to any value. Do not make any assumptions on the contents of the given memory.

bool SoMemManagerBitCheck u8   bmdata,
u16    bitnum
[inline]
 

tests to see if bit in bitmap is set

Parameters:
bmdata  pointer to start of bitmap
bitnum  bit number to check

For internal use only.

Yes, I realize this isn't the most efficient way to do this...

void SoMemManagerBitClear u8   bmdata,
u16    bitnum
[inline]
 

clears a bit in a bitmap

Parameters:
bmdata  pointer to start of bitmap
bitnum  bit number to clear

For internal use only.

Yes, I realize this isn't the most efficient way to do this...

void SoMemManagerBitSet u8   bmdata,
u16    bitnum
[inline]
 

sets a bit in a bitmap

Parameters:
bmdata  pointer to start of bitmap
bitnum  bit number to set

For internal use only.

Yes, I realize this isn't the most efficient way to do this...

void SoMemManagerFree void *    pMemPool,
void *    pBuf
 

Release memory back to free pool.

Parameters:
pMemPool  The starting address of the free pool. Must have been previously initialized by calling SoMemManagerInit (this argument is omitted if SO_MEM_MANAGER_SINGLE_POOL_BASE is define'd)
pBuf  Pointer to the buffer to free. Must have been previously created via a call to SoMemManagerAlloc
This releases the memory back into the pool. Only call this function with pointers you received from SoMemManagerAlloc or results will be unpredictable.

After this function is called the contents of the released memory is unpredictable and modifying it will likely cause a crash. Never make any assumptions about the memory after giving it to SoMemManagerFree.

void SoMemManagerInit u32   pMemPool,
u32    iBufSize,
u16    iBlockSize
 

initialize memory pool for allocation

Parameters:
pMemPool  The starting address of the free pool to be initialized. Must be aligned on a 4-byte boundary. (this argument is omitted if SO_MEM_MANAGER_SINGLE_POOL_BASE is define'd)
iBufSize  The number of bytes reserved for the free pool, including space for memory manager overhead. (this argument is omitted if SO_MEM_MANAGER_SINGLE_POOL_SIZE is define'd)
iBlockSize  The number of bytes per allocation block. The larger this value, the more space will be wasted per allocation. Must be a power of 2 greater than 8. (this argument is omitted if SO_MEM_MANAGER_BLOCK_BITS is define'd)
Call this fucntion before you use any other SoMemManager functions.

void SoMemManagerInsertNode u32   pMemPool,
u16    iParentNode,
struct SoMemManagerNode_t   pParentNode,
u16    iInsNode
[static]
 

insert new node into (subtree of) free node tree

Parameters:
pMemPool  the memory pool (this argument is omitted if SO_MEM_MANAGER_SINGLE_POOL_BASE is define'd)
iParentNode  subtree index to insert into
pParentNode  subtree pointer to insert into
iInsNode  index of node to be inserted

For internal use only.

void SoMemManagerRemoveNode u32   pMemPool,
u16    iNode,
struct SoMemManagerNode_t   pNode
[static]
 

Remove specified node from free pool tree.

Parameters:
pMemPool  the memory pool (this argument is omitted if SO_MEM_MANAGER_SINGLE_POOL_BASE is define'd)
iNode  index of node to be removed
pNode  pointer to node to be removed

For internal use only.


Copyright 2002 by the SGADE authors. See SoLicense.h or Visit the SGADE page for more information.