473,889 Members | 1,559 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1238
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*******@yaho o.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*******@yaho o.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******** ************@ne ws000.worldonli ne.dk...

"Gaurav Jain" <my*******@yaho o.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*****@hotmai l.com> skrev i en meddelelse
news:j5******** *************@b gtnsc04-news.ops.worldn et.att.net...

"Peter Koch Larsen" <pk*****@mailme .dk> wrote in message
news:QT******** ************@ne ws000.worldonli ne.dk...

"Gaurav Jain" <my*******@yaho o.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
2096
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 while executing in .Net and visual slick editor. why it didn't allocate memory? if anybody knows plz give reply. thanks in advance kk
6
8217
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 allocation to create object of that class ? 2. If it says "dynamic memory allocation", is it mean the following code : DestinationAddress* dest = new DestinationAddress(); // code 1
4
6777
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 = Linux galahad 2.4.19-64GB-SMP #1 SMP /etc/sysctl.conf kernel.shmmax=268435456
74
4725
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 seems to be setting a NULL pointer to the end of the list, and here we know that the allocated memory has been exhausted. All good. When this is a pointer to another type, say int, I could have a variable that records how much memory is being...
62
17906
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(); img.src = ; Then I use the image a few more times by adding it into an Array object:
66
3676
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 (function(socket, args) == -1) { perror("function"); exit(EXIT_FAILURE); } I feel that the ifs destroy the readability of my code. Would it be
24
19115
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 is faster than malloc, but dynamic memory allocation is more flexible. Please comment... thanks.
1
7984
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 compiled and run without any erros but the second program has a run time error when the function return from allocate and the ptr become NULL. How to fixed this? Second Program: /* Best Method to allocate memory for 2D Array because it's ...
1
1728
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 all is how variables are created in what type of memory and how they are deleted in the following three cases when calling and exiting test, test1 and test2 functions. I also note that I see a different result while using char and char* which I...
66
3733
by: karthikbalaguru | last post by:
Hi, Will 'free' return the memory Immediately to the OS ? Thx in advans, Karthik Balaguru
0
9809
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11190
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10442
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7993
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7150
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6029
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4647
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4251
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3256
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.