Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

UnpackMemMan Class Reference

#include <UnpackMem.hpp>

List of all members.

Public Methods

char Init (unsigned long myneededmemoryspace, unsigned long datablockcount)
UnpackDataBlockAllocateDataBlocks (unsigned long len)


Member Function Documentation

UnpackDataBlock* UnpackMemMan::AllocateDataBlocks unsigned long    len [inline]
 

Definition at line 72 of file UnpackMem.hpp.

00073    {
00074       UnpackDataBlock *firstdatablock=NULL,**lastdatablockref=&firstdatablock;
00075 
00076       while(lastblock->used+sizeof(UnpackDataBlock)+len>lastblock->len)
00077          // As long as the data block does not fit onto the current memblock
00078          // We must allocate more space !
00079       {
00080          if(lastblock->used+sizeof(UnpackDataBlock)+MIN_DATABLOCKSIZE<lastblock->len)
00081             // If there is a certain minimum space, then we can at least use parts of the
00082             // block
00083          {
00084             *lastdatablockref=(UnpackDataBlock *)((char *)(lastblock+1)+lastblock->used);
00085             (*lastdatablockref)->len=lastblock->len-lastblock->used-sizeof(UnpackDataBlock);
00086             (*lastdatablockref)->next=NULL;
00087 
00088             len-=(*lastdatablockref)->len;
00089             neededmemoryspace-=(*lastdatablockref)->len;
00090 
00091             lastblock->used=lastblock->len;
00092 
00093             lastdatablockref=&((*lastdatablockref)->next);
00094          }
00095 
00096          // Now, we allocate a new block
00097 
00098          lastblock=AllocateMemBlock(&(lastblock->next));
00099          if(lastblock==NULL)
00100             return NULL;
00101 
00102          lastblock=lastblock->next;
00103       }
00104 
00105       *lastdatablockref=(UnpackDataBlock *)((char *)(lastblock+1)+lastblock->used);
00106       (*lastdatablockref)->len=len;
00107       (*lastdatablockref)->next=NULL;
00108 
00109       neededmemoryspace-=len+sizeof(UnpackDataBlock);
00110 
00111       lastblock->used+=sizeof(UnpackDataBlock)+len;
00112 
00113       return firstdatablock;
00114    }

char UnpackMemMan::Init unsigned long    myneededmemoryspace,
unsigned long    datablockcount
[inline]
 

Definition at line 59 of file UnpackMem.hpp.

00060    {
00061       neededmemoryspace=myneededmemoryspace+datablockcount*sizeof(UnpackDataBlock);
00062       curmaxblocksize=MAX_BLOCKSIZE;
00063 
00064       // Let's see if we can already allocate as much as possible
00065       lastblock=AllocateMemBlock(&firstblock);
00066       if(lastblock==NULL)
00067          return -1;
00068 
00069       return 0;
00070    }


The documentation for this class was generated from the following file:
Generated on Sat Oct 13 16:08:56 2001 for XMILL by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001