C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

overloading new() and delete() for a collection of classes

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
spipyeah
Guest





PostPosted: Fri Feb 27, 2004 6:10 pm    Post subject: overloading new() and delete() for a collection of classes Reply with quote



When writing a C library, I typically export a routine to the client
code can call to set the allocation and deallocation reoutines that my
library should use.

I'm having trouble doing the same with a C++ library I'm writing. My
first instinct was to overload new and delete for my library
namespace, but it still seemed to be conflicting with the global new
and delete operators.

Does this mean I should overload new & delete in every class my
library contains, and within those overloaded operators use the
allocation and deallocation routines that were set for my library?

Thank you,
spip

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Thomas Richter
Guest





PostPosted: Sun Feb 29, 2004 3:59 am    Post subject: Re: overloading new() and delete() for a collection of class Reply with quote



Hi,

Quote:
When writing a C library, I typically export a routine to the client
code can call to set the allocation and deallocation reoutines that my
library should use.

I'm having trouble doing the same with a C++ library I'm writing. My
first instinct was to overload new and delete for my library
namespace, but it still seemed to be conflicting with the global new
and delete operators.

Does this mean I should overload new & delete in every class my
library contains, and within those overloaded operators use the
allocation and deallocation routines that were set for my library?

Hmm. Someone should really put this onto a FAQ. (-;

One possible solution (that works in my practical application, exactly
for a C++ library with custom allocators) is mentioned in the thread
"Overloading the new operator" from Feb. 14th, on exactly this group. My
posting to Kurt Stege presented one possible solution.

Basically, you define a base class with a placement operator new all
your objects are derived from that takes over the allocation. This
placement operator takes a pool argument to perform the allocation. A
suitable overloaded delete operator will return the memory to the pool.

So long,
Thomas



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.