Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

lemur::utility::MemCache Class Reference

#include <MemCache.hpp>

List of all members.

Public Member Functions

 MemCache (int cachesize)
 MemCache (int *cache, int cachesize)
 use the given memory

 MemCache ()
 ~MemCache ()
int * getMem (int chunksize)
int * getMoreMem (int newsize, int *location, int oldsize)
void freeMem (int *location, int memsize)
void flushMem ()
const int * getBegin ()
const int * getEnd ()

Private Member Functions

int * getFromFree (int csize)

Private Attributes

int * begin
int size
 point to the start of our cache

int * end
 the size of our cache

int intsize
 index of where free memory begins

vector< int * > freelist [NLISTS]
 sizeof(int) value

bool ourmem
 array of lists of free memory

Detailed Description

This is a cache for managing memory. You allocate a chunk of memory and request pointers to smaller pieces of it. You can also trade memory for bigger pieces. It will copy stuff over for you. This cache will only hand out memory in chunk sizes of powers of 2 from 2^10 through 2^22.

Constructor & Destructor Documentation

lemur::utility::MemCache::MemCache int  cachesize  ) 


cachesize how much memory to allocate this cache in bytes

lemur::utility::MemCache::MemCache int *  cache,
int  cachesize

use the given memory

lemur::utility::MemCache::MemCache  ) 

default constructor that doesn't do much

lemur::utility::MemCache::~MemCache  ) 

destructor free the memory we allocated

Member Function Documentation

void lemur::utility::MemCache::flushMem  ) 


void lemur::utility::MemCache::freeMem int *  location,
int  memsize

"free" the memory at this pointer this cache will remember it in the free list this does not mean delete the memory

location beginning of location of memory
memsize how much to free at this location

const int * lemur::utility::MemCache::getBegin  ) 

const int * lemur::utility::MemCache::getEnd  ) 

int * lemur::utility::MemCache::getFromFree int  csize  )  [private]

returns pointer to memory holes if available returns NULL if nothing is available

csize size of memory we're requesting

int * lemur::utility::MemCache::getMem int  chunksize  ) 

a pointer to some memory location of size chunksize
chunksize how much memory we need in bytes as a power of 2,

int * lemur::utility::MemCache::getMoreMem int  newsize,
int *  location,
int  oldsize

returns pointer to a new location of newsize containing all the elements of the old location

NULL if we can't get more memory, or if we are requesting a newsize that is not bigger than the oldsize

Member Data Documentation

int* lemur::utility::MemCache::begin [private]

int* lemur::utility::MemCache::end [private]

the size of our cache

vector<int*> lemur::utility::MemCache::freelist[NLISTS] [private]

sizeof(int) value

int lemur::utility::MemCache::intsize [private]

index of where free memory begins

bool lemur::utility::MemCache::ourmem [private]

array of lists of free memory

int lemur::utility::MemCache::size [private]

point to the start of our cache

The documentation for this class was generated from the following files:
Generated on Tue Jun 15 11:03:07 2010 for Lemur by doxygen 1.3.4