#include <stdlib.h>
#include "MemMan.hpp"
Go to the source code of this file.
Functions | |
char * | AllocateBlockRecurs (unsigned char blocksizeidx) |
Variables | |
unsigned long | allocatedmemory = 0 |
unsigned long | blocksizes [BLOCKSIZE_NUM] |
char * | freeblocklists [BLOCKSIZE_NUM] = {NULL,NULL,NULL,NULL} |
|
Definition at line 51 of file MemMan.cpp. 00055 { 00056 char *ptr; 00057 00058 // Do we have any free block? 00059 if(freeblocklists[blocksizeidx]!=NULL) 00060 { 00061 ptr=freeblocklists[blocksizeidx]; 00062 freeblocklists[blocksizeidx]=*(char **)freeblocklists[blocksizeidx]; 00063 return ptr; 00064 } 00065 else 00066 { 00067 if(blocksizeidx==BLOCKSIZE_NUM-1) 00068 // Is this the largest possible block size?? 00069 // We must allocate new space! 00070 { 00071 ptr=(char *)malloc(blocksizes[blocksizeidx]); 00072 if(ptr==NULL) 00073 ExitNoMem(); 00074 00075 return ptr; 00076 } 00077 else // If we haven't reached the largest possible block size, 00078 // We allocate a block of the next larger block size 00079 // and use it as a container for our blocks 00080 { 00081 ptr=AllocateBlockRecurs(blocksizeidx+1); 00082 00083 // We add the new blocks to the free list 00084 char *ptr1=ptr+blocksizes[blocksizeidx], 00085 *endptr=ptr+blocksizes[blocksizeidx+1]; 00086 00087 do 00088 { 00089 *(char **)ptr1=freeblocklists[blocksizeidx]; 00090 freeblocklists[blocksizeidx]=ptr1; 00091 00092 ptr1+=blocksizes[blocksizeidx]; 00093 } 00094 while(ptr1<endptr); 00095 00096 return ptr; 00097 } 00098 } 00099 } |
|
Definition at line 38 of file MemMan.cpp. |
|
Initial value: Definition at line 40 of file MemMan.cpp. |
|
Definition at line 45 of file MemMan.cpp. |