29 #ifndef ALLOCATOR_INCLUDED
30 #define ALLOCATOR_INCLUDED
53 std::vector<T*> memory;
56 blockSize=index=remains=0;
65 for(std::size_t i=0;i<memory.size();i++){
delete[] memory[i];}
67 blockSize=index=remains=0;
84 for(std::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();
111 for(
int j=0;j<remains;j++){
112 memory[index][j].~T();
113 new(&memory[index][j]) T();
119 for(
int j=0;j<state.
remains;j<remains){
120 memory[index][j].~T();
121 new(&memory[index][j]) T();
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);
158 mem=&(memory[index][blockSize-remains]);
168 #endif // ALLOCATOR_INCLUDE