Re: shared memory object classes

New Message Reply Date view Thread view Subject view Author view

Martin Roth (roth++at++ifi.unizh.ch)
Fri, 24 Feb 1995 23:50:45 +0100


Lance R Marrou wrote:

> I am curious if it is possible to use the operator new to allocate an object
> class in shared memory. I tried most (if not all) combinations like:
>
> po = ::new(sizeof(printobj),pfGetSharedArena()) printobj();
> po = new(sizeof(printobj),pfGetSharedArena()) printobj();
> po = new(pfGetSharedArena()) printobj();
>
> These were just some simple test cases, I have much more complicated classes
> in mind. What seems to work is this:
>
> po = (printobj *)pfMalloc(sizeof(printobj),pfGetSharedArena());
>
> But then I need a fake constructor to call after allocation.

Hi Lance,

I'm doing this in my application through overloading of the new and delete
operators of all my classes:

        void *operator new(size_t sz, void *a) { return pfMalloc(sz, a); }
        void *operator new(size_t sz) { return pfMalloc(sz, NULL); }
        void operator delete(void *addr) { pfFree(addr); }

Allocating an object in shared memory is done through:

        obj = new(pfGetSharedArena()) Object();

and of course the constructor is called as always.

Does this help?

Martin

_______________________________________________________________________________
 /| /|) S. H. Martin Roth
/ |/ |\OTH Student in Computer Science

ETHZ, Swiss Federal Institute of Technology Zuerich email: sroth++at++iiic.ethz.ch
UniZh, University of Zuerich email: roth++at++ifi.unizh.ch


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:51:00 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.