An AllocRing is a bounded ring (circular list), each of whose elements contains a pointer to some space allocated via new char[some_size]
. The entries are used cyclicly. The size, n, of the ring is fixed at construction. After that, every nth use of the ring will reuse (or reallocate) the same space. AllocRings are needed in order to temporarily hold chunks of space that are needed transiently, but across constructor-destructor scopes. They mainly useful for storing strings containing formatted characters to print across various functions and coercions. These strings are needed across routines, so may not be deleted in any one of them, but should be recovered at some point. In other words, an AllocRing is an extremely simple minded garbage collection mechanism. The GNU C++ library used to use one AllocRing for such formatting purposes, but it is being phased out, and is now only used by obsolete functions. These days, AllocRings are probably not very useful.
Support includes:
AllocRing a(int n)
void* mem = a.alloc(sz)
int present = a.contains(void* ptr)
a.clear()
a.free(void* ptr)