Thread View: comp.std.c++
1 messages
1 total messages
Started by Claus Andre Faerber
Mon, 04 Dec 1995 22:33
Re: new syntax for new operator
Author: Claus Andre Faerber
Date: Mon, 04 Dec 1995 22:33
Date: Mon, 04 Dec 1995 22:33
96 lines
3455 bytes
3455 bytes
pierreba@poster.cae.ca (30 Nov 95):
>[...]
> -- Start example --
>
> class A
> {
> public:
> // default new for static variables.
> static void operator new ( void *, size_t );
> // overloaded new for static variables.
> static void operator new ( void *, size_t, int a, int b );
> // delete for static variables.
> static void operator delete ( void *, size_t );
>
> // default new for auto variables.
> auto void operator new ( void *, size_t );
> // overloaded new for auto variables.
> auto void operat+7 " >/w 2 c+e_t, int a, int b );
> // delete for auto variables.
> auto void operator delete ( void *, size_t );
> };
>
> static A a2; // static A object using declared default new.
> static A a2 = new (88,91) A; // static A object using overloaded new.
>
> int main (void)
> {
> A a3; // auto A object with declared default new.
> A a4 = new (88,91) A; // auto A object with overloaded new.
This sytax is inconsistent with the existing one: new always return a
poiter to the object created.
> ...
>
> } // at this point the declared delete operator is called for each A
>
> -- End example --
Another point is, that you don't need a new operator for static and auto
objects, as they have reserved space in the data segment ("static-heap")
or on the stack, which is allocated at compile time.
Therefore you can't create static or auto objects with sizes calculated at
run time, either.
>[...]
> Usage of the new operators are multiples. The first is the possibility to
> distinguish between stack-allocated, static-heap and dynamic-heap
> variables. Many programs need that capability, notably when related to
> smart pointers and garbage collection. Another usage (the one which
> prompted me to write this) would be in the context of OODBMS. The
> ability to communicate with the server and take different actions depending
> on the location of the variable can dramatically improve the performance
> of some operations.
I suggest defining a new syntax for *constructors* (or any member
functions) instead:
class A
{
A ( ); // Perhaps we should create a new keyword like
A ( int abc ); // "dynamic" for heap objects.
A ( ) static;
A ( int abc ) static;
A ( ) auto;
A ( int abc ) auto;
DoSomething ( int* xyz );
DoSomething ( int* xyz ) static;
DoSomething ( int* xyz ) auto;
~A( );
~A( ) static;
~A( ) auto;
};
This also meets the syntax used by many compiler vendors to differentiate
far and near methodes.
>[...]
===================================================
Claus Andre Faerber <claus@faerber.muc.de>
===================================================
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads