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

  • Thread starter HeroOfSpielburg
  • Start date
H

HeroOfSpielburg

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
 
A

Alf P. Steinbach

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top