Var makes it so users don't have to worry about their array bounds. Scalars allocated in bulk do not.
The idea of present is abstract and unresearched. Basically, we create a structure to proxy for each scalar*, such as int* or double*. A second proxy (or perhaps just the class of the first) will be used with calls to new[], having that operator overloaded.
So, in int_allocator::operator new[] (size_t sz), we do something like this: value = new int[sz+1]; *value++ = sz;
Treating the struct as an int* will work just like a regular int*, but more operators could be overloaded to ensure correct performance. #define is also an option; this is just a debug mode.
Upon access via the other class, int_proxy, the allocator class will be decremented and dereferenced for a bounds check.
|