Go forward to Concept Index.
Go backward to Exception Handling.
Go up to Top.
Free Store
==========
operator new [] adds a magic cookie to the beginning of arrays for
which the number of elements will be needed by operator delete [].
These are arrays of objects with destructors and arrays of objects that
define operator delete [] with the optional size_t argument. This
cookie can be examined from a program as follows:
typedef unsigned long size_t;
extern "C" int printf (const char *, ...);
size_t nelts (void *p)
{
struct cookie {
size_t nelts __attribute__ ((aligned (sizeof (double))));
};
cookie *cp = (cookie *)p;
--cp;
return cp->nelts;
}
struct A {
~A() { }
};
main()
{
A *ap = new A[3];
printf ("%ld\n", nelts (ap));
}
Linkage
=======
The linkage code in g++ is horribly twisted in order to meet two
design goals:
1) Avoid unnecessary emission of inlines and vtables.
2) Support pedantic assemblers like the one in AIX.
To meet the first goal, we defer emission of inlines and vtables
until the end of the translation unit, where we can decide whether or
not they are needed, and how to emit them if they are.