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
void initialize(int alngth, int iacnt, int acnt, int rsrvstr, int rsrvrefstr)
Initializes sizes where alngth is the size of the arrays to be provided to requesting clients...
Definition: ArrayReuse.h:331
int getUnusedArrayCount() const
Returns the current number of unused allocated arrays.
Definition: ArrayReuse.h:367
void reuseArray(T *a)
Returns an array that was being used by a client back into the reuse pool.
Definition: ArrayReuse.h:238
Definition: ArrayReuse.h:55
int getAllocatedArrays() const
Returns the total number of allocated arrays (each of arrayLength).
Definition: ArrayReuse.h:351
void initialize(int alngth, int acnt)
Initializes sizes where alngth is the size of the arrays to be provided to requesting clients...
Definition: ArrayReuse.h:285
An array reuse object for cases where arrays of some fixed type and size are required by the applicat...
Definition: ArrayReuse.h:70
T * getArray()
Returns a new array of size arrayLength for use by requesting clients.
Definition: ArrayReuse.h:224
ArrayReuse(int alngth, int acnt)
Standard constructor where alngth is the size of the arrays to be provided to requesting clients...
Definition: ArrayReuse.h:164
ArrayReuse(int alngth, int iacnt, int acnt)
Standard constructor where alngth is the size of the arrays to be provided to requesting clients...
Definition: ArrayReuse.h:183
ArrayReuse()
Default constructor.
Definition: ArrayReuse.h:146
An exception class for all GeoTess objects.
Definition: GeoTessException.h:65
ArrayReuse(int alngth, int iacnt, int acnt, int rsrvstr, int rsrvrefstr)
Standard constructor where alngth is the size of the arrays to be provided to requesting clients...
Definition: ArrayReuse.h:208
void initialize(int alngth, int iacnt, int acnt)
Initializes sizes where alngth is the size of the arrays to be provided to requesting clients...
Definition: ArrayReuse.h:306
int getUsedArrayCount() const
Returns the number of arrays currently in use by clients.
Definition: ArrayReuse.h:359
void resetIfRequired()
Calls reset if the size of refStore is not equal to the total number of allocated arrays (allocArrays...
Definition: ArrayReuse.h:265
int getArrayLength() const
Returns the array length setting.
Definition: ArrayReuse.h:375
#define GEOTESS_EXP_IMP
Definition: CPPGlobals.h:71
virtual ~ArrayReuse()
Destructor.
Definition: ArrayReuse.h:215
void reset()
Resets refStore to all allocated references in store.
Definition: ArrayReuse.h:249