Topic: Proposal: some kind of default_global_new_handler()
Author: fjh@cs.mu.OZ.AU (Fergus Henderson)
Date: Wed, 1 Nov 2000 15:45:38 GMT Raw View
"Ken Bloom" <ken195@bigfoot.com> writes:
>Usually to overload operator new for a class, one allocates the memory used
>by the class by calling new char[size] to allocate the memory (unless the
>purpose of the overload was to change this). I was recently attempting to
>write a global operator new that would fill all newly allocated memory with
>a debugging byte to make it easier to find uninitialied data, and was trying
>to figure out what the best way to allocate the new memory was in this case
>(noting that new char[size] would cause a runaway recursion).I eventually
>had to settle on malloc(), even though malloc() and operator new aren't even
>guaranteed to allocate memory on the same heap.
>
>Why is there no function void* default_operator_new(size_t) function that I
>can use from within global operator new to allocate the memory I need to
>use?
When you override operator new(), generaly you must override all the
standard forms of it, and operator delete(), to ensure that they are
consistent. If you do that, then there's nothing wrong with using
malloc() and free() as the underlying allocator.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
| of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: "Ken Bloom" <ken195@bigfoot.com>
Date: Tue, 31 Oct 2000 16:46:16 GMT Raw View
Usually to overload operator new for a class, one allocates the memory used
by the class by calling new char[size] to allocate the memory (unless the
purpose of the overload was to change this). I was recently attempting to
write a global operator new that would fill all newly allocated memory with
a debugging byte to make it easier to find uninitialied data, and was trying
to figure out what the best way to allocate the new memory was in this case
(noting that new char[size] would cause a runaway recursion).I eventually
had to settle on malloc(), even though malloc() and operator new aren't even
guaranteed to allocate memory on the same heap.
Why is there no function void* default_operator_new(size_t) function that I
can use from within global operator new to allocate the memory I need to
use?
--
Ken Bloom
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS/M/AT/U d- s++:--- a--- C++ UL P++ L+ E----
W+++ N++ ?o ?K w++ !O M++>$ V- PS PE Y-- PGP- t+
5 X++ R--- tv-- b++ DI+ D-- G e- !h r--@ y?
------END GEEK CODE BLOCK------
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]