This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Question about implementation of new/delete and new[]/delete[] in gnu gcc
- From: Florian Weimer <fw at deneb dot enyo dot de>
- To: Tim Schumacher <schumact at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Wed, 13 Mar 2013 16:13:53 +0100
- Subject: Re: Question about implementation of new/delete and new[]/delete[] in gnu gcc
- References: <513EC4DB.1010301@gmail.com>
* Tim Schumacher:
> Specifically, I was curious about what meta data is stored about the
> allocations (size/# of elements in the array case), and where that
> data is stored.
Certain types require a "cookie" which stores the length, and it is
stored just before the pointer that operator new[] returns. The rules
for when a cookie is needed are somewhat complex and depend on the ABI
version. The layout of the cookie field is ABI-dependent as well
(beyond mere differences in word size).
Searching for "cookie" in gcc/cp/*.c should point you into the right
direction.
operator new[] is expanded in-line by the compiler, so most of the
run-time library support routines Jonathan mentioned are not actually
used by GCC, but are provided for use by other compilers.