473,405 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 1222
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: kk | last post by:
Hi all, i didn't get output in the following code while compiling and executing with g++ version 3.2.3 it doesn't allocate memory to pointer varaible (x) in class B. and it gives correct output...
6
by: chris | last post by:
Hi all, I need to know, what is the difference between dynamic memory allocation, and stack allocation ? 1. If I have a class named DestinationAddress, when should I use dynamic memory...
4
by: PaulR | last post by:
Hi, We have a Server running SLES 8 and 3GB memory, with 1 DB2 instance and 2 active Databases. General info... DB2level = "DB2 v8.1.0.72", "s040914", "MI00086", and FixPak "7" uname -a =...
74
by: ballpointpenthief | last post by:
If I have malloc()'ed a pointer and want to read from it as if it were an array, I need to know that I won't be reading past the last index. If this is a pointer to a pointer, a common technique...
62
by: ivan.leben | last post by:
How can I really delete a preloaded image from memory/disk cache? Let's say I preload an image by creating an Image object and setting its src attribute to desired URL: var img = new Image();...
66
by: Johan Tibell | last post by:
I've written a piece of code that uses sockets a lot (I know that sockets aren't portable C, this is not a question about sockets per se). Much of my code ended up looking like this: if...
24
by: Ken | last post by:
In C programming, I want to know in what situations we should use static memory allocation instead of dynamic memory allocation. My understanding is that static memory allocation like using array...
1
by: Peterwkc | last post by:
Hello all expert, i have two program which make me desperate bu after i have noticed the forum, my future is become brightness back. By the way, my problem is like this i the first program was...
1
by: krishna81m | last post by:
In the following code, I am trying to return a char, a char* (a type of non-const without using new, what do we call this type of pointer?) and char* created using new operator. What I do not know at...
66
by: karthikbalaguru | last post by:
Hi, Will 'free' return the memory Immediately to the OS ? Thx in advans, Karthik Balaguru
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.