36 #ifndef ARRAYREUSE_OBJECT_H
37 #define ARRAYREUSE_OBJECT_H
83 int arraysAddedPerAlloc;
89 int initArraysAddedPerAlloc;
115 void add(
int count) {
116 store.push_back(
new T[count * arrayLength]);
117 for (
int i = 0; i < count; ++i)
118 refStore.push_back(&store.back()[i * arrayLength]);
120 allocArrays += count;
127 if ((
int)refStore.size() != allocArrays)
130 os << endl <<
"ERROR in ArrayReuse::destroy()" << endl
131 << allocArrays <<
" arrays have been allocated but "
132 << allocArrays - refStore.size()
133 <<
" of them have not been returned." << endl;
137 for (
int i = 0; i < (int) store.size(); ++i)
147 arrayLength(1), arraysAddedPerAlloc(1), allocArrays(0) {
165 initialize(alngth, acnt, acnt, 8, acnt + acnt);
184 initialize(alngth, iacnt, acnt, 8, iacnt + acnt);
208 ArrayReuse(
int alngth,
int iacnt,
int acnt,
int rsrvstr,
int rsrvrefstr) {
209 initialize(alngth, iacnt, acnt, rsrvstr, rsrvrefstr);
225 if (refStore.size() == 0)
226 add(arraysAddedPerAlloc);
228 T* a = refStore.back();
239 refStore.push_back(a);
251 for (
int i = 0; i < (int) store.size(); ++i)
255 initArraysAddedPerAlloc :
256 arraysAddedPerAlloc); ++j) {
257 refStore.push_back(&store[i][j * arrayLength]);
266 if ((
int) refStore.size() != allocArrays)
286 initialize(alngth, acnt, acnt, 8, acnt + acnt);
307 initialize(alngth, iacnt, acnt, 8, iacnt + acnt);
331 void initialize(
int alngth,
int iacnt,
int acnt,
int rsrvstr,
339 arrayLength = alngth;
340 arraysAddedPerAlloc = acnt;
341 initArraysAddedPerAlloc = iacnt;
342 store.reserve(rsrvstr);
343 refStore.reserve(rsrvrefstr);
360 return allocArrays - (int) refStore.size();
368 return (
int) refStore.size();
384 #endif // ARRAYREUSE_OBJECT_H