[comp.lang.c++] -fthis-is-variable

samples@manzanita.berkeley.edu (A. Dain Samples) (04/12/90)

Could someone send me a reference on the use of the new user-defined
free store management capability?  (I.e. how do I get rid of
-fthis-is-variable off my invocation line.)

Thanks!

Dain

brad@bnrmtl.UUCP (Brad Fowlow) (04/12/90)

In answer to some questions that have come up lately,
here is a quick description abstracted from the C++ manual.
I *believe* this stuff works in g++, but I haven't tried it lately.

To control allocation and deallocation of objects yourself,
declare member operators new and delete:

class A {
   void* operator new(size_t sz);
   void operator delete (A* p_a);
};

Inheritance, access rules, and so on are as for other classes
(the size argument is needed because you'd normally define the operator
at some base class level and use it for derived classes).

The implementation of these functions could just call 'malloc' and 'free',
for example, or whatever you want.

Once defined, the use of these functions is transparent.
Just say 'new A' and you get what you want.

A wrinkle: you can overload the operators new and delete.
If you declare extra arguments after size_t,
say,
   operator new (size_t, char*);
you call that version by saying
   A* p_a = new ("extra operator new arg") A ( /* ctor arguments */ );   


Hope this is enough to get folks going.
No guarantees.

brad fowlow