469,943 Members | 2,581 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,943 developers. It's quick & easy.

Memory allocation using New

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
Jul 23 '05 #1
7 1134
Gaurav Jain wrote:
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 ?


Not only the information itself, but also the place where it is stored
depends on the compiler and the library implementation.

Jul 23 '05 #2
What this information may be ?

"Rolf Magnus" <ra******@t-online.de> wrote in message
news:d8*************@news.t-online.com...
Gaurav Jain wrote:
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 ?


Not only the information itself, but also the place where it is stored
depends on the compiler and the library implementation.

Jul 23 '05 #3

"Gaurav Jain" <my*******@yahoo.com> wrote in message
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


I assume you mean "new"? There is no "New" defined in C++.

And yes, it's compiler-dependent what information gets stored. And where.
There is no requirement that such information be stored at any particular
place.

-Howard
Jul 23 '05 #4

"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
Jul 23 '05 #5

"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

Jul 23 '05 #6


Gaurav Jain wrote:
"Rolf Magnus" <ra******@t-online.de> wrote in message
news:d8*************@news.t-online.com...
Gaurav Jain wrote:
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 ?
Not only the information itself, but also the place where it is stored
depends on the compiler and the library implementation.

What this information may be ?

Please don't top-post. Your reply belongs following or interspersed
with the quoted material.
That information is completely outside the realm of the user. What
information and where it is kept is implementation-specific and is not
topical here. If you really must know, you'll need to find a newsgroup
dedicated to your platform (compiler/OS).

Brian

Jul 23 '05 #7

"Howard" <al*****@hotmail.com> skrev i en meddelelse
news:j5*********************@bgtnsc04-news.ops.worldnet.att.net...

"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.

[snip]

Correct. But that does not imply that the size needs to be explicitly stored
anywhere. Most likely it will not be, unless it is a "large" object.
-Howard

/Peter
Jul 23 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by kk | last post: by
74 posts views Thread by ballpointpenthief | last post: by
62 posts views Thread by ivan.leben | last post: by
66 posts views Thread by Johan Tibell | last post: by
66 posts views Thread by karthikbalaguru | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.