Overloading new[] and delete[]: how do they vary from new and delete?

Discussion in 'C++' started by HeroOfSpielburg, Aug 6, 2003.

  1. I'm writing a memory manager and overloading the operators "::new" and
    "::delete" I know this isn't always the smartest thing to do, but
    regardless, I was wondering what sort of considerations I should be
    making when writing the array-based versions "new[]" and "delete[]"
    (in contrast to the single item "new" and "delete").

    I know the fundamental issue between ensuring "new[]" is matched with
    "delete[]" is making sure the destructor for each of the items in the
    dynamically-allocated array is called (as opposed to just the first if
    only "delete" were called). If I'm just getting a pointer to the
    beginning of said array when "delete[]" is called, how do I handle
    this properly?

    Thanks in advance.

    Dave
     
    HeroOfSpielburg, Aug 6, 2003
    #1
    1. Advertising

  2. On 5 Aug 2003 20:22:36 -0700, (HeroOfSpielburg) wrote:

    >I'm writing a memory manager


    That's not a good idea except as an exercise.

    To write a (useful) memory manager you need to really know
    what you're doing.

    Take a look in "Modern C++ Design" and in the Boost library.


    >...
    >If I'm just getting a pointer to the
    >beginning of said array when "delete[]" is called, how do I handle
    >this properly?


    You don't. Your responsibility is not to call destructors but to
    deallocate memory. Whatever the latter means in your code.
     
    Alf P. Steinbach, Aug 6, 2003
    #2
    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. Ryan Moore

    Vary by custom

    Ryan Moore, Jan 27, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    4,710
    GeekyMonkey
    Aug 24, 2006
  2. Replies:
    7
    Views:
    491
  3. Taras_96
    Replies:
    3
    Views:
    306
    Taras_96
    Apr 14, 2008
  4. vary number of loops

    , Apr 16, 2008, in forum: Python
    Replies:
    6
    Views:
    294
  5. Tomás Ó hÉilidhe

    Finite list of things that vary with CPU-type

    Tomás Ó hÉilidhe, Dec 4, 2008, in forum: C Programming
    Replies:
    16
    Views:
    616
    Ben Bacarisse
    Dec 7, 2008
Loading...

Share This Page