"Peter Koch Larsen" <pk*****@mailme.dk> wrote in message
news:QT********************@news000.worldonline.dk ...
"Gaurav Jain" <my*******@yahoo.com> skrev i en meddelelse
news:d8********@netnews.proxy.lucent.com... Hi,
While New() is used for allocating objects on heap some additional
information is stored before the begning of the block so that delete can
release the allocated memory.
Any idea what this information is just the size or anything else also ?
is
it dependent on the compiler used ?
Regards,
Gaurav
Why should you store anything besides the object? This is not necessary in
the general case. Perhaps you are thinking about new[] where the
application MIGHT store the number of elements allocated. But again,
there's no need to store anything.
/Peter
When freeing memory, even for a single object, the amount of memory
originally allocated needs to be known (by something, somewhere), in order
to restore the right amount of memory to the system. And that applies even
at the low level of malloc/free, not just new/delete. How such information
is kept is not specified by the standard, however. Some OS or hardware may
handle such details for you. It's not something that, at least in general,
a C++ programmer should bother worrying about.
To the OP: why are you asking? Is there a problem you're trying to resolve,
or just curious?
-Howard