Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Overloading new[] and delete[]: how do they vary from new and delete?

Reply
Thread Tools

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

 
 
HeroOfSpielburg
Guest
Posts: n/a
 
      08-06-2003
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
 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      08-06-2003
On 5 Aug 2003 20:22:36 -0700, http://www.velocityreviews.com/forums/(E-Mail Removed) (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.

 
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
template parameter that can also vary at runtime Taras_96 C++ 3 04-14-2008 04:38 AM
FAQ: how to vary the byte offset of a field of a ctypes.Structure p.lavarre@ieee.org Python 7 06-04-2007 03:53 PM
Vary by custom Ryan Moore ASP .Net 4 08-24-2006 03:26 PM
they turn, they power, they make nice pics Keith and Jenn Z. Digital Photography 0 09-21-2003 04:16 AM



Advertisments