Working of the delete [ ] operator

Discussion in 'C++' started by Megha Vishwanath, Oct 15, 2003.

  1. 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.
     
    Megha Vishwanath, Oct 15, 2003
    #1
    1. Advertising

  2. Megha Vishwanath

    tom_usenet Guest

    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
     
    tom_usenet, Oct 15, 2003
    #2
    1. Advertising

  3. Megha Vishwanath

    Rolf Magnus Guest

    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.
     
    Rolf Magnus, Oct 15, 2003
    #3
  4. Thanx Tom!
     
    Megha Vishwanath, Oct 15, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sandeep Grover

    delete on delete !

    Sandeep Grover, Jul 12, 2003, in forum: C++
    Replies:
    19
    Views:
    636
    Chris \( Val \)
    Jul 22, 2003
  2. HeroOfSpielburg
    Replies:
    1
    Views:
    397
    Alf P. Steinbach
    Aug 6, 2003
  3. Jef Driesen
    Replies:
    1
    Views:
    509
    Gernot Frisch
    Jan 19, 2005
  4. Amy
    Replies:
    13
    Views:
    6,027
    Kurt Stutsman
    Feb 23, 2005
  5. tom
    Replies:
    5
    Views:
    413
Loading...

Share This Page