|
[16.14] After p = new Fred[n], how does the compiler know there are n objects to be destructed during delete[] p?
Short answer: Magic.
Long answer: The run-time system stores the number of objects, n,
somewhere where it can be retrieved if you only know the pointer, p.
There are two popular techniques that do this. Both these techniques are in
use by commercial-grade compilers, both have tradeoffs, and neither is
perfect. These techniques are:
|