00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifdef USE_ALLOCATOR
00036
00037 #include "../allocator/allocator.h"
00038 #include "../prof/prof.h"
00039
00040 void* Allocator::get( size_t unitSize) {
00041
00042 if( !_unitSize) _unitSize = unitSize;
00043
00044 if( !_freeUnits) allocNewBlock();
00045
00046 void* unit = _freeUnits;
00047 _freeUnits = *(void**)_freeUnits;
00048
00049 return unit;
00050 }
00051
00052 void Allocator::put( void* unit) {
00053
00054 *(void**)unit = _freeUnits;
00055 _freeUnits = unit;
00056 }
00057
00058 void Allocator::allocNewBlock() {
00059
00060 size_t len = _unitSize*NUM_UNITS_IN_BLOCK+sizeof( void*);
00061
00062 char* block = ::new char[len];
00063
00064 *(void**)(block+len-sizeof( void*)) = _blocks;
00065 _blocks = block;
00066
00067 char* unit = block;
00068
00069 for( int i = 0; i < NUM_UNITS_IN_BLOCK; i++, unit += _unitSize) {
00070
00071 *(void**)unit = _freeUnits;
00072 _freeUnits = unit;
00073 }
00074 }
00075
00076 Allocator::~Allocator() {
00077
00078 size_t len = _unitSize*NUM_UNITS_IN_BLOCK+sizeof( void*);
00079
00080 void* del;
00081 while( del = _blocks) {
00082
00083 _blocks = *(void**)((char*)_blocks+len-sizeof( void*));
00084 ::delete[] (char*)del;
00085 }
00086 }
00087
00088 #endif
00089