 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
spipyeah Guest
|
Posted: Fri Feb 27, 2004 6:10 pm Post subject: overloading new() and delete() for a collection of classes |
|
|
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
|
Posted: Sun Feb 29, 2004 3:59 am Post subject: Re: overloading new() and delete() for a collection of class |
|
|
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 |
|
 |
|
|
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
|
|