# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

NLMISC::CHeapMemory Class Reference

A Heap manager. More...

#include <heap_memory.h>

List of all members.

Public Methods

 CHeapMemory ()
 Constructor. More...

 ~CHeapMemory ()
void reset ()
 reset the entire container. NB: no free() is made on the heap. More...

void initHeap (void *heap, uint size, uint align=4)
 init the heap. More...

uint getHeapSize () const
 return the size passed in setHeap(). More...

uint getHeapSizeUsed () const
 return the heap size allocated. More...

void * allocate (uint size)
 allocate a block of size bytes. More...

void free (void *ptr)
 free a block allocated with alloate(). no-op if NULL. nlstop() if don't find this block. More...


Private Types

typedef std::multimap< uint,
uint8 * > 
TEmptySpaceSizeMap
typedef TEmptySpaceSizeMap::iterator ItEmptySpaceSizeMap
typedef std::map< uint8 *,
CEmptySpace
TEmptySpacePtrMap
typedef TEmptySpacePtrMap::iterator ItEmptySpacePtrMap
typedef std::map< uint8 *,
uint
TAllocatedSpaceMap
typedef TAllocatedSpaceMap::iterator ItAllocatedSpaceMap

Private Methods

void removeEmptySpace (CEmptySpace &space)
void addEmptySpace (CEmptySpace &space)

Private Attributes

uint8_HeapPtr
uint _HeapSize
uint _HeapSizeUsed
uint _Alignment
TEmptySpacePtrMap _EmptySpaces
 The array of empty spaces. More...

TEmptySpaceSizeMap _EmptySpaceMap
 for allocate method, the size -> empty space map. More...

TAllocatedSpaceMap _AllocatedSpaceMap


Detailed Description

A Heap manager.

Work with any kind of memory. This heap manager is not designed for speed (because it stills use standard heap allocation), but for use with special memory or special cases where malloc/new cannot be used.

Author:
Lionel Berenguier , Nevrax France
Date:
2001

Definition at line 46 of file heap_memory.h.


Member Typedef Documentation

typedef TAllocatedSpaceMap::iterator NLMISC::CHeapMemory::ItAllocatedSpaceMap [private]
 

Definition at line 106 of file heap_memory.h.

Referenced by free.

typedef TEmptySpacePtrMap::iterator NLMISC::CHeapMemory::ItEmptySpacePtrMap [private]
 

Definition at line 101 of file heap_memory.h.

Referenced by free.

typedef TEmptySpaceSizeMap::iterator NLMISC::CHeapMemory::ItEmptySpaceSizeMap [private]
 

Definition at line 85 of file heap_memory.h.

Referenced by allocate.

typedef std::map<uint8*, uint> NLMISC::CHeapMemory::TAllocatedSpaceMap [private]
 

Definition at line 105 of file heap_memory.h.

typedef std::map<uint8*, CEmptySpace> NLMISC::CHeapMemory::TEmptySpacePtrMap [private]
 

Definition at line 100 of file heap_memory.h.

typedef std::multimap<uint, uint8*> NLMISC::CHeapMemory::TEmptySpaceSizeMap [private]
 

Definition at line 84 of file heap_memory.h.


Constructor & Destructor Documentation

NLMISC::CHeapMemory::CHeapMemory  
 

Constructor.

Definition at line 38 of file heap_memory.cpp.

References _Alignment, and reset.

NLMISC::CHeapMemory::~CHeapMemory  
 

Definition at line 45 of file heap_memory.cpp.

References reset.


Member Function Documentation

void NLMISC::CHeapMemory::addEmptySpace CEmptySpace   space [private]
 

Definition at line 107 of file heap_memory.cpp.

References _EmptySpaceMap, and _EmptySpaces.

Referenced by allocate, free, and initHeap.

void * NLMISC::CHeapMemory::allocate uint    size
 

allocate a block of size bytes.

return NULL if not enough space or if size==0. NB: for alignements consideration, allocation are aligned to 4 bytes.

Definition at line 118 of file heap_memory.cpp.

References _Alignment, _AllocatedSpaceMap, _EmptySpaceMap, _EmptySpaces, _HeapSizeUsed, addEmptySpace, ItEmptySpaceSizeMap, and removeEmptySpace.

Referenced by NL3D::CVertexBufferHeap::allocate, NL3D::CVertexArrayRangeATI::allocateVB, and NL3D::CVertexArrayRangeNVidia::allocateVB.

void NLMISC::CHeapMemory::free void *    ptr
 

free a block allocated with alloate(). no-op if NULL. nlstop() if don't find this block.

Definition at line 173 of file heap_memory.cpp.

References _AllocatedSpaceMap, _EmptySpaces, _HeapSizeUsed, addEmptySpace, ItAllocatedSpaceMap, ItEmptySpacePtrMap, nlassert, nlstop, and removeEmptySpace.

Referenced by NL3D::CVertexBufferHeap::free, NL3D::CVertexArrayRangeATI::freeVB, and NL3D::CVertexArrayRangeNVidia::freeVB.

uint NLMISC::CHeapMemory::getHeapSize   const [inline]
 

return the size passed in setHeap().

Definition at line 67 of file heap_memory.h.

References _HeapSize.

uint NLMISC::CHeapMemory::getHeapSizeUsed   const [inline]
 

return the heap size allocated.

Definition at line 69 of file heap_memory.h.

References _HeapSizeUsed.

void NLMISC::CHeapMemory::initHeap void *    heap,
uint    size,
uint    align = 4
 

init the heap.

this reset() the heap. heap ptr is stored in this class, but no CHeapMemory methods write or read into. They use standard heap instead (new / delete).

Parameters:
heap  the heap ptr. heap should be at least N-bytes aligned, where N is the alignment you need (see param align, 4 by default).
align  Any size given to allocate() will be rounded to match this alignement. Valid values are 4,8,16, or 32. 4 by default.

Definition at line 64 of file heap_memory.cpp.

References _Alignment, _HeapPtr, _HeapSize, _HeapSizeUsed, addEmptySpace, nlstop, and reset.

Referenced by NL3D::CVertexArrayRangeATI::allocate, NL3D::CVertexArrayRangeNVidia::allocate, and NL3D::CVertexBufferHeap::init.

void NLMISC::CHeapMemory::removeEmptySpace CEmptySpace   space [private]
 

Definition at line 96 of file heap_memory.cpp.

References _EmptySpaceMap, and _EmptySpaces.

Referenced by allocate, and free.

void NLMISC::CHeapMemory::reset  
 

reset the entire container. NB: no free() is made on the heap.

Definition at line 52 of file heap_memory.cpp.

References _AllocatedSpaceMap, _EmptySpaceMap, _EmptySpaces, _HeapPtr, _HeapSize, and _HeapSizeUsed.

Referenced by CHeapMemory, NL3D::CVertexArrayRangeATI::free, NL3D::CVertexArrayRangeNVidia::free, initHeap, and ~CHeapMemory.


Member Data Documentation

uint NLMISC::CHeapMemory::_Alignment [private]
 

Definition at line 113 of file heap_memory.h.

Referenced by allocate, CHeapMemory, and initHeap.

TAllocatedSpaceMap NLMISC::CHeapMemory::_AllocatedSpaceMap [private]
 

Definition at line 120 of file heap_memory.h.

Referenced by allocate, free, and reset.

TEmptySpaceSizeMap NLMISC::CHeapMemory::_EmptySpaceMap [private]
 

for allocate method, the size -> empty space map.

Definition at line 118 of file heap_memory.h.

Referenced by addEmptySpace, allocate, removeEmptySpace, and reset.

TEmptySpacePtrMap NLMISC::CHeapMemory::_EmptySpaces [private]
 

The array of empty spaces.

Definition at line 116 of file heap_memory.h.

Referenced by addEmptySpace, allocate, free, removeEmptySpace, and reset.

uint8* NLMISC::CHeapMemory::_HeapPtr [private]
 

Definition at line 110 of file heap_memory.h.

Referenced by initHeap, and reset.

uint NLMISC::CHeapMemory::_HeapSize [private]
 

Definition at line 111 of file heap_memory.h.

Referenced by getHeapSize, initHeap, and reset.

uint NLMISC::CHeapMemory::_HeapSizeUsed [private]
 

Definition at line 112 of file heap_memory.h.

Referenced by allocate, free, getHeapSizeUsed, initHeap, and reset.


The documentation for this class was generated from the following files: