Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Working of the delete [ ] operator

Reply
Thread Tools

Working of the delete [ ] operator

 
 
Megha Vishwanath
Guest
Posts: n/a
 
      10-15-2003
Hi,

I'd like to know how heap aggregates created with a "new" operator at
non-contiguous memory locations get deallocated using the "delete []"
operator in VC++.

A garbage collectors in Java deallocate on the basis of a record
maintained during the "new" allocation.

Do we use something like a garbage collector to maintain arecord of
the heap memory start indexes.

Please enlighten me.

Thanks,

Megha.
 
Reply With Quote
 
 
 
 
tom_usenet
Guest
Posts: n/a
 
      10-15-2003
On 15 Oct 2003 03:08:52 -0700, (Megha Vishwanath)
wrote:

>Hi,
>
>I'd like to know how heap aggregates created with a "new" operator at


You mean the new[] operator?

>non-contiguous memory locations get deallocated using the "delete []"
>operator in VC++.


There is a header before the bit of memory that new[] returns that
gives the size of the allocated block. A call to delete[] then uses
this size to
a) work out how many objects to destruct
b) actually deallocate the memory

>A garbage collectors in Java deallocate on the basis of a record
>maintained during the "new" allocation.


Same in C++ - the memory allocator keeps track of the size of
allocations. Different allocators do this differently.

>
>Do we use something like a garbage collector to maintain arecord of
>the heap memory start indexes.


No. You should read up on memory allocators:

http://www.memorymanagement.org

Tom
 
Reply With Quote
 
 
 
 
Rolf Magnus
Guest
Posts: n/a
 
      10-15-2003
tom_usenet wrote:

> On 15 Oct 2003 03:08:52 -0700, (Megha Vishwanath)
> wrote:
>
>>Hi,
>>
>>I'd like to know how heap aggregates created with a "new" operator at

>
> You mean the new[] operator?
>
>>non-contiguous memory locations get deallocated using the "delete []"
>>operator in VC++.

>
> There is a header before the bit of memory that new[] returns that
> gives the size of the allocated block. A call to delete[] then uses
> this size to
> a) work out how many objects to destruct
> b) actually deallocate the memory


Just to mention: That's one way to do it. The C++ standard doesn't
specify how this is to be done, and there are other ways.

 
Reply With Quote
 
Megha Vishwanath
Guest
Posts: n/a
 
      10-15-2003
Thanx Tom!
 
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
delete MyClass doing more than MyClass::operator delete()? tom C++ 5 07-14-2006 06:21 PM
How to redefine operator delete/delete[] via macro? Amy C++ 13 02-23-2005 03:36 AM
Mixing new/delete and operator new/delete? Jef Driesen C++ 1 01-19-2005 01:56 PM
Operator overloading on "default" operator John Smith C++ 2 10-06-2004 10:22 AM
Q: operator void* or operator bool? Jakob Bieling C++ 2 03-05-2004 04:27 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57