38 #ifndef ARRAYREUSE_OBJECT_H
39 #define ARRAYREUSE_OBJECT_H
85 int arraysAddedPerAlloc;
91 int initArraysAddedPerAlloc;
117 void add(
int count) {
118 store.push_back(
new T[count * arrayLength]);
119 for (
int i = 0; i < count; ++i)
120 refStore.push_back(&store.back()[i * arrayLength]);
122 allocArrays += count;
129 if ((
int)refStore.size() != allocArrays)
132 os << endl <<
"ERROR in ArrayReuse::destroy()" << endl
133 << allocArrays <<
" arrays have been allocated but "
134 << allocArrays - refStore.size()
135 <<
" of them have not been returned." << endl;
139 for (
int i = 0; i < (int) store.size(); ++i)
149 arrayLength(1), arraysAddedPerAlloc(1), allocArrays(0) {
167 initialize(alngth, acnt, acnt, 8, acnt + acnt);
186 initialize(alngth, iacnt, acnt, 8, iacnt + acnt);
210 ArrayReuse(
int alngth,
int iacnt,
int acnt,
int rsrvstr,
int rsrvrefstr) {
211 initialize(alngth, iacnt, acnt, rsrvstr, rsrvrefstr);
227 if (refStore.size() == 0)
228 add(arraysAddedPerAlloc);
230 T* a = refStore.back();
241 refStore.push_back(a);
253 for (
int i = 0; i < (int) store.size(); ++i)
257 initArraysAddedPerAlloc :
258 arraysAddedPerAlloc); ++j) {
259 refStore.push_back(&store[i][j * arrayLength]);
268 if ((
int) refStore.size() != allocArrays)
288 initialize(alngth, acnt, acnt, 8, acnt + acnt);
309 initialize(alngth, iacnt, acnt, 8, iacnt + acnt);
333 void initialize(
int alngth,
int iacnt,
int acnt,
int rsrvstr,
341 arrayLength = alngth;
342 arraysAddedPerAlloc = acnt;
343 initArraysAddedPerAlloc = iacnt;
344 store.reserve(rsrvstr);
345 refStore.reserve(rsrvrefstr);
362 return allocArrays - (int) refStore.size();
370 return (
int) refStore.size();
386 #endif // ARRAYREUSE_OBJECT_H