29 #ifndef ALLOCATOR_INCLUDED
30 #define ALLOCATOR_INCLUDED
50 std::vector< T* > memory;
52 Allocator(
void ){ blockSize = index = remains = 0; }
59 for(
size_t i=0;i<memory.size();i++){
delete[] memory[i];}
61 blockSize=index=remains=0;
81 for(
size_t i=0 ; i<memory.size() ; i++ )
83 for(
int j=0 ; j<blockSize ; j++ )
86 new(&memory[i][j]) T();
99 if(state.
index<index){
100 for(
int j=state.
remains;j<blockSize;j++){
101 memory[state.
index][j].~T();
102 new(&memory[state.
index][j]) T();
104 for(
int i=state.
index+1;i<index-1;i++){
105 for(
int j=0;j<blockSize;j++){
107 new(&memory[i][j]) T();
110 for(
int j=0;j<remains;j++){
111 memory[index][j].~T();
112 new(&memory[index][j]) T();
118 for(
int j=0;j<state.
remains;j<remains){
119 memory[index][j].~T();
120 new(&memory[index][j]) T();
132 this->blockSize = blockSize;
145 if( !elements )
return NULL;
146 if( elements>blockSize ) fprintf( stderr ,
"[ERROR] Allocator: elements bigger than block-size: %d>%d\n" , elements , blockSize ) , exit( 0 );
147 if( remains<elements )
149 if( index==memory.size()-1 )
151 mem =
new T[blockSize];
152 if( !mem ) fprintf( stderr ,
"[ERROR] Failed to allocate memory\n" ) , exit(0);
153 memory.push_back( mem );
158 mem = &(memory[index][blockSize-remains]);
void rollBack(const AllocatorState &state)
AllocatorState getState(void) const
T * newElements(int elements=1)