|
|
Up |
|
|
  |
Author: xushiweixushiwei Date: Apr 30, 2008 02:20
I have another suggestion about memory management of ISO C++. I think
it is very IMPORTANT. And I hope it can be discussed in C++0x.
----
A proposal to cancel overriding the DEFAULT operator new/delete
I don't think we need to override the DEFAULT operator new/delete.
This makes your code doesn't work well together 3rdparty code (if it
also override them).
I suggest ISO C++ cancel this feature, just like we can't override
operator+ of all C types. That is:
1. You CAN NOT override these operators:
void* operator new(size_t size);
void operator delete(void* p);
2. You CAN override NON-DEFAULT operator new. Such as:
void* operator new(size_t size, my_allocator& alloc);
3. There is no need to override operator delete. If you need delete
objects in special way, just use:
alloc.destroy(obj);
That's all.
Thanks.
|
| Show full article (0.99Kb) |
|
| | 11 Comments |
|
  |
Author: Tony DelroyTony Delroy Date: Apr 30, 2008 08:36
On Apr 30, 7:13 pm, xushiwei gmail.com> wrote:
> I don't think we need to override the DEFAULT operator new/delete.
> This makes your code doesn't work well together 3rdparty code (if it
> also override them).
>
> I suggest ISO C++ cancel this feature, just like we can't override
> operator+ of all C types. That is:
Practically, there's no way this will happen, as lots of existing code
makes use of this feature. If you think there's a problem, put your
effort into finding a way of structuring the resolution of memory
requests to avoid the issues you're experiencing, and if other people
see the merits, you might get it into a later C++ standard. Simply
banning everything is about as practical as asking the UN to make it
illegal for 3rd party libraries to include thread-unsafe code, or
requiring all libraries to be in namespaces registered with a global
body....
Tony
|
| Show full article (1.03Kb) |
|
| | no comments |
|
  |
Author: Francis GlassborowFrancis Glassborow Date: Apr 30, 2008 08:36
xushiwei wrote:
> I have another suggestion about memory management of ISO C++. I think
> it is very IMPORTANT. And I hope it can be discussed in C++0x.
Forget it, it won't happen. Even if the Standards' Committees were not
in the final stages of developing C++0x it would still not happen
because your proposal gratuitously breaks existing code.
|
| Show full article (1.33Kb) |
| no comments |
|
  |
|
Author: xushiweixushiwei Date: Apr 30, 2008 15:11
|
| |
| no comments |
|
  |
Author: Tony DelroyTony Delroy Date: Apr 30, 2008 20:28
On May 1, 8:02 am, xushiwei gmail.com> wrote:
> I don't agree that my proposal [to disallow overriding
> default operator new/delete] breaks existing code. The
>compilers of C ++0x have a lot of ways to solve this.
> For example, the compilers can
> skip overriding operator new/delete and use the default
> implementation. And they can give a warning that reminds programmers
> to eliminate useless codes. Why do I think to cancel overriding the
> DEFAULT operator new/delete is possible? Because overriding the
> DEFAULT operator new/delete only change the implementation, not the
> semantic (the concept). If implementations changes the semantic of
> DEFAULT operator new/delete, they are bad code indeed.
|
| Show full article (1.45Kb) |
| no comments |
|
  |
|
|
  |
Author: xushiweixushiwei Date: May 2, 2008 11:10
http://xushiwei.com/cancel-overriding-the-default-operator-new-delete
* Motivation
I don't think we need to override the DEFAULT operator new/delete.
This makes your code doesn't work well together 3rdparty code (if it
also overrides them).
Why overriding the DEFAULT operator new/delete is bad?
Allowing to override the DEFAULT operator new/delete means the DEFAULT
operator new/delete are special operators. When we have more than one
implementations of an operator, the compiler/linker will report...
|
| Show full article (2.64Kb) |
| no comments |
|
  |
Author: xushiweixushiwei Date: May 2, 2008 11:12
{ clc++m uses English. It would be nicer for other English-only-speaking
readers if the attribution line used English and the whole article used
an encoding such as US-ASCII, ISO-8859 or UTF-8 that more English-based
systems have support for, though none of these is a rejection reason.
-mod }
On 4月30日, 下午9时16分, Tony Delroy yahoo.co.uk> wrote:
> Why do you think existing code bothers to override the default
> operator new/delete? It's typically not just for the sake of it.
> Clearly it achieves some purpose: particular performance
> characteristics, instrumentation, validations, supports some
> functionality like persistence, who knows? You don't. I'm confident
> that the C++ standards committee wouldn't simply presume that it's not
> important to the application - in the face of the fact that the
> programmer thought is was important enough to code in the first place
> - and can be arbitrarily discarded, regardless of how you implore them.
Why overriding the DEFAULT operator new/delete is bad?
Allowing to override the DEFAULT operator new/delete means the DEFAULT
operator new/delete are special operators. When we have more than one
implementations of an operator, the compiler/linker will report...
|
| Show full article (1.99Kb) |
| no comments |
|
  |
Author: Stephen HoweStephen Howe Date: May 3, 2008 04:20
> Why overriding the DEFAULT operator new/delete is bad?
>
> Allowing to override the DEFAULT operator new/delete means the DEFAULT
> operator new/delete are special operators. When we have more than one
> implementations of an operator, the compiler/linker will report a
> redefining error. However, it allows there are two implementations of
> the DEFAULT operator new/delete (one of them is implemented as
> default). It sounds good. But, This gives a hint that there may have
> many implementations of the DEFAULT operator new/delete. When this
> happens, the compiler/linker doesn't know what should it do
If your proposal ever got off the ground, how do you expect the authors of
the 3rd party library to use the compiler to compile their version of
operator new/delete?
Because your change means the compiler vendor should ignore the 3rd party
library's operator new/delete and prefer its own version.
In any case, it does not work like this.
It is usually the case that the programmers versions of
functions/data/objects etc are preferred by the linker before searching
libraries for missing symbols.
|
| Show full article (1.27Kb) |
| no comments |
|
  |
|
|
  |
Author: Francis GlassborowFrancis Glassborow Date: May 3, 2008 14:10
xushiwei wrote:
I can say with 100%% certainty that this proposal will NOT be considered
by WG21 and J16 for C++0x. Even if you could persuade us that it has
enough merit to justify breaking existing code and the coding techniques
that rely on the facility it is years too late for consideration.
That means that you have plenty of time to persuade people that your
proposal has sufficient merit to justify consideration for the standard
after C++0x. Frankly I think you would be wasting your time but you are
welcome to try.
|
| Show full article (0.92Kb) |
| no comments |
|
|
|
|