473,503 Members | 2,197 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

delete[]

AS
Hello,
consider the following statements,
int *pBuf = new int[10]; //this will allocate 10*sizeof(int) memory

delete []pBuf // this will delete all the memory allocated to pBuf

Question: How come the application knows that it has to delete memory of
pBuf for 10 * sizeof(int) from the statement "delete []pBuf "?
Pls. reply back
John
Dec 24 '07 #1
6 1718
On 2007-12-24 00:57:39 -0500, "AS" <as**********@rediffmail.comsaid:
Hello,
consider the following statements,
int *pBuf = new int[10]; //this will allocate 10*sizeof(int) memory

delete []pBuf // this will delete all the memory allocated to pBuf

Question: How come the application knows that it has to delete memory of
pBuf for 10 * sizeof(int) from the statement "delete []pBuf "?
Pls. reply back
John
Same way how free() knows how much memory to reclaim from malloc(): It
keeps internal data structure on what pieces of memory were issued.

--

-kira

Dec 24 '07 #2
AS
Thanx for the reply. I guessed the same. Can you explain in detail or any
sample code to demonstrate this ?

"Kira Yamato" <ki*****@earthlink.netwrote in message
news:2007122400425016807-kirakun@earthlinknet...
On 2007-12-24 00:57:39 -0500, "AS" <as**********@rediffmail.comsaid:
>Hello,
consider the following statements,
int *pBuf = new int[10]; //this will allocate 10*sizeof(int) memory

delete []pBuf // this will delete all the memory allocated to pBuf

Question: How come the application knows that it has to delete memory of
pBuf for 10 * sizeof(int) from the statement "delete []pBuf "?
Pls. reply back
John

Same way how free() knows how much memory to reclaim from malloc(): It
keeps internal data structure on what pieces of memory were issued.

--

-kira

Dec 24 '07 #3
"Kira Yamato" <ki*****@earthlink.netwrote in message
news:2007122400425016807-kirakun@earthlinknet...
>On 2007-12-24 00:57:39 -0500, "AS" <as**********@rediffmail.com>
said:
>>Hello,
consider the following statements,
int *pBuf = new int[10]; //this will allocate 10*sizeof(int)
memory delete []pBuf // this will delete all the memory allocated to
pBuf Question: How come the application knows that it has to delete
memory of pBuf for 10 * sizeof(int) from the statement "delete
[]pBuf "?
>Same way how free() knows how much memory to reclaim from malloc(): It
keeps internal data structure on what pieces of memory were
issued.
Thanx for the reply. I guessed the same. Can you explain in detail or
any sample code to demonstrate this ?
It's the compiler/OS that keeps track. It may be done differently in
different compilers and OSes. I think you gave the perfect example, what
more would you need?

--
Jim Langston
ta*******@rocketmail.com
Dec 24 '07 #4
AS
I would like to know how this is happening internally, suppose that if we
have to write our own Memory Manager which handle these ?

"Jim Langston" <ta*******@rocketmail.comwrote in message
news:Ne*************@newsfe05.lga...
>"Kira Yamato" <ki*****@earthlink.netwrote in message
news:2007122400425016807-kirakun@earthlinknet...
>>On 2007-12-24 00:57:39 -0500, "AS" <as**********@rediffmail.com>
said:
Hello,
consider the following statements,
int *pBuf = new int[10]; //this will allocate 10*sizeof(int)
memory delete []pBuf // this will delete all the memory allocated
to
pBuf Question: How come the application knows that it has to delete
memory of pBuf for 10 * sizeof(int) from the statement "delete
[]pBuf "?
>>Same way how free() knows how much memory to reclaim from malloc(): It
keeps internal data structure on what pieces of memory were
issued.
>Thanx for the reply. I guessed the same. Can you explain in detail or
any sample code to demonstrate this ?

It's the compiler/OS that keeps track. It may be done differently in
different compilers and OSes. I think you gave the perfect example, what
more would you need?

--
Jim Langston
ta*******@rocketmail.com

Dec 24 '07 #5
AS wrote:
Please don't top-post.
"Jim Langston" <ta*******@rocketmail.comwrote in message
news:Ne*************@newsfe05.lga...
>>"Kira Yamato" <ki*****@earthlink.netwrote in message
news:2007122400425016807-kirakun@earthlinknet...
On 2007-12-24 00:57:39 -0500, "AS" <as**********@rediffmail.com>
said:
Hello,
consider the following statements,
int *pBuf = new int[10]; //this will allocate 10*sizeof(int)
memory delete []pBuf // this will delete all the memory allocated
to
pBuf Question: How come the application knows that it has to delete
memory of pBuf for 10 * sizeof(int) from the statement "delete
[]pBuf "?
Same way how free() knows how much memory to reclaim from malloc(): It
keeps internal data structure on what pieces of memory were
issued.
Thanx for the reply. I guessed the same. Can you explain in detail or
any sample code to demonstrate this ?
It's the compiler/OS that keeps track. It may be done differently in
different compilers and OSes. I think you gave the perfect example, what
more would you need?
Or quote signatures.
>>
I would like to know how this is happening internally, suppose that if we
have to write our own Memory Manager which handle these ?
The answer is part of your operating system or runtime libraries. If
you can , consult the source for those. Writing your own memory manager
is an excellent way to understand the problems involved with dynamic
memory management.

--
Ian Collins.
Dec 24 '07 #6
On Dec 24, 12:43*pm, "AS" <asudhakar...@rediffmail.comwrote:
I would like to know how this is happening internally, suppose that if we
have to write our own Memory Manager which handle these ?
Consider going through the C++ FAQ lite -
http://www.parashift.com/c++-faq-lit...html#faq-16.14
Dec 24 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2568
by: Dave | last post by:
Hello all, In the code below, I see the following output: base::operator new(size_t, int) base::base() base::~base() base::operator delete(void *) In the case of an exception being thrown...
1
3828
by: Nimmi Srivastav | last post by:
There's a rather nondescript book called "Using Borland C++" by Lee and Mark Atkinson (Que Corporation) which presents an excellent discussion of overloaded new and delete operators. In fact there...
3
9354
by: Nimmi Srivastav | last post by:
There's a rather nondescript book called "Using Borland C++" by Lee and Mark Atkinson (Que Corporation) which presents an excellent discussion of overloaded new and delete operators. I am...
1
3873
by: Douglas Peterson | last post by:
class Allocator { public: virtual void * Alloc(size_t) = 0; virtual void * Free(void*) = 0; }; class Object { public:
2
2070
by: Dave | last post by:
Hello all, I'd like to find a source on the web that discusses, in a comprehensive manner and in one place, everything about new / delete. It should include overloading operator new, the new...
3
4633
by: silver360 | last post by:
Hello, I'm trying to create a basic Heap manager and i have some question about new/delete overloading. The following code give me this output : >> $./heap >> registered : 0x804d098 >>...
9
8146
by: rohits123 | last post by:
I have an overload delete operator as below ////////////////////////////////// void operator delete(void* mem,int head_type) { mmHead local_Head = CPRMemory::GetMemoryHead(head_type);...
10
2071
by: jeffjohnson_alpha | last post by:
We all know that a new-expression, foo* a = new foo() ; allocates memory for a single foo then calls foo::foo(). And we know that void* p = ::operator new(sizeof(foo)) ; allocates a...
15
4991
by: LuB | last post by:
I am constantly creating and destroying a singular object used within a class I wrote. To save a bit of time, I am considering using 'placement new'. I guess we could also debate this decision -...
29
2222
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, I remembered delete is implemented through operator overloading, but I am not quite clear. Could anyone recommend some links about how delete is implemented so that I can...
0
7093
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
7349
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...
1
7008
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
4688
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...
0
3177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3168
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
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 ...
1
746
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
399
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...

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.