Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > how does the delete function release the memory?

Reply
Thread Tools

how does the delete function release the memory?

 
 
=?gb2312?B?wNbA1rTzzOzKpg==?=
Guest
Posts: n/a
 
      01-27-2007
struct elem
{
int a;
int b;
};


elem * p = new elem[20];
delete []p;
//-----will the text above memory leak?

 
Reply With Quote
 
 
 
 
Alan Johnson
Guest
Posts: n/a
 
      01-27-2007
????? wrote:
> struct elem
> {
> int a;
> int b;
> };
>
>
> elem * p = new elem[20];
> delete []p;
> //-----will the text above memory leak?
>


No. That is the correct usage of new[] and delete[]. Are you asking
how delete[] knows how many elements you allocated? That depends on your
implementation, but one possible way is that it allocates a few extra
bytes before the pointer that is returned, in which the number of
elements is stored.

See the FAQ 16.14 for details of this and another method.
http://www.parashift.com/c++-faq-lit...html#faq-16.14

--
Alan Johnson
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
FAQ 5.38 Why does Perl let me delete read-only files? Why does "-i" clobber protected files? Isn't this a bug in Perl? PerlFAQ Server Perl Misc 0 02-11-2011 05:00 AM
Delete does not really delete Hong Chen C++ 2 06-16-2008 08:49 PM
Why does "delete" not delete? D. Susman C++ 11 03-11-2008 10:03 PM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM



Advertisments