Topic: can i overload new[] and delete[] ?


Author: pjunold@daimi.aau.dk (Peter Joachim Unold)
Date: 18 Mar 1995 23:29:27 GMT
Raw View
Subject says it all. Watcom10 and bc45 allowed me to overload
the 2 operators, while g++ didn't. I can't find it mentioned
anywhere in my now 4 year old Stroustrup book, that new[] is
a seperate operator, so I wonder if it's a new thing in
standard c++?

Another somewhat related question:
When the global new and delete operators are overloaded,
should all heap allocations from standard functions/classes
go through these operators? Are there any rules on this?
In other words can I force the standard functions only to acquire
memory through my overloaded new/delete operators.

 best regards
   peter unold - pjunold@daimi.aau.dk




Author: jason@cygnus.com (Jason Merrill)
Date: 19 Mar 1995 02:39:43 GMT
Raw View
>>>>> Peter Joachim Unold <pjunold@daimi.aau.dk> writes:

> Subject says it all. Watcom10 and bc45 allowed me to overload
> the 2 operators, while g++ didn't.

You have an old version of g++.  This feature was added in 2.6.0.

> When the global new and delete operators are overloaded,
> should all heap allocations from standard functions/classes
> go through these operators? Are there any rules on this?
> In other words can I force the standard functions only to acquire
> memory through my overloaded new/delete operators.

That is the default, unless there are new/delete operators for the specific
classes.

Unless you're referring to malloc, which is completely separate from
new/delete, and should probably be avoided in C++ programs (in favor of
explicit calls to operator new).

Jason




Author: kuehl@uzwil (Dietmar Kuehl)
Date: 21 Mar 1995 16:13:26 GMT
Raw View
hi,

Peter Joachim Unold (pjunold@daimi.aau.dk) wrote:
: Subject says it all. Watcom10 and bc45 allowed me to overload
: the 2 operators, while g++ didn't. I can't find it mentioned
: anywhere in my now 4 year old Stroustrup book, that new[] is
: a seperate operator, so I wonder if it's a new thing in
: standard c++?

the operators new[] and delete[] are present in Stroupstrup's
second edition of "The C++ Programming Language". However, at the
time of writing this book these two operators could not be overloaded.
In ANSI/ISO C++ it is possible to overload these two operators.
Overloading of these operators is not yet supported by all available
compilers. The current version of gcc (2.6.3) allows overloading.
:
: Another somewhat related question:
: When the global new and delete operators are overloaded,
: should all heap allocations from standard functions/classes
: go through these operators? Are there any rules on this?
: In other words can I force the standard functions only to acquire
: memory through my overloaded new/delete operators.

There is only one global version of new, delete, new[] and delete[].
Heap allocations/deallocations not mode through one of these four
operators can only made by an overloaded member function of some class
(or struct). There is no way and no rule (in the C++ language itself,
software design rules excluded...) to prohibit such allocations.

:  best regards
:    peter unold - pjunold@daimi.aau.dk

dk
--
"We will encourage you to develop the three great virtues of a
programmer: laziness, impatience, and hubris" (from: "Programming
Perl", O'Reilly & Associates, Inc.)