29 #ifndef ALLOCATOR_INCLUDED 30 #define ALLOCATOR_INCLUDED 53 std::vector<T*> memory;
56 blockSize=index=remains=0;
65 for(
size_t i=0;i<memory.size();i++){
delete[] memory[i];}
67 blockSize=index=remains=0;
84 for(
size_t i=0;i<memory.size();i++){
85 for(
int j=0;j<blockSize;j++){
87 new(&memory[i][j]) T();
100 if(state.
index<index){
101 for(
int j=state.
remains;j<blockSize;j++){
102 memory[state.
index][j].~T();
103 new(&memory[state.
index][j]) T();
105 for(
int i=state.
index+1;i<index-1;i++){
106 for(
int j=0;j<blockSize;j++){
108 new(&memory[i][j]) T();
112 memory[
index][j].~T();
113 new(&memory[
index][j]) T();
120 memory[
index][j].~T();
121 new(&memory[
index][j]) T();
130 void set(
int blockSize){
132 this->blockSize=blockSize;
144 if(!elements){
return NULL;}
145 if(elements>blockSize){
146 fprintf(stderr,
"Allocator Error, elements bigger than block-size: %d>%d\n",elements,blockSize);
149 if(remains<elements){
150 if(index==memory.size()-1){
151 mem=
new T[blockSize];
152 if(!mem){fprintf(stderr,
"Failed to allocate memory\n");exit(0);}
153 memory.push_back(mem);
168 #endif // ALLOCATOR_INCLUDE
void rollBack(const AllocatorState &state)
This method rolls back the allocator to the previous memory state and makes all of the memory previou...
This templated class assists in memory allocation and is well suited for instances when it is known t...
void rollBack(void)
This method rolls back the allocator so that it makes all of the memory previously allocated availabl...
AllocatorState getState(void) const
This method returns the memory state of the allocator.
void reset(void)
This method is the allocators destructor.
T * newElements(int elements=1)
This method returns a pointer to an array of elements objects.