Martin Roth (roth++at++ifi.unizh.ch)
Fri, 24 Feb 1995 23:50:45 +0100
> 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
This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:51:00 PDT