Re: Performer and C++

New Message Reply Date view Thread view Subject view Author view

Marcus Barnes (marcus++at++multigen.com)
Thu, 17 Apr 1997 12:10:35 -0700


On Apr 17, 9:46am, Guy Premont wrote:
> On Wed, 16 Apr 1997, Steve Baker wrote:
> > The basic mechanism is to overload 'operator new' and 'operator delete' for
> > all classes that you want to place in shared memory.
>
> Would it be possible to use a Performer base class, like pfMemory or
> pfObject, to do just the same?

Yes.

> I'm thinking about:
> class MyOwnClass : public pfMemory
> {
> [...class definition...]
> }
>
> which would allows the use of:
> MyOwnClass *object = new(pfGetSharedArena()) MyOwnClass;

No it wont. This will end up calling ::new( size_t, void* ) which will
instantly corrupt your arena.

pfMemory::operator new() has different syntax than you expect. Different even
than pfObject::operator new(). pfMemory declares:

    // operator to catch bad usage
    void* operator new(size_t s);

Therefore "pfMemory* m = new pfMemory;" is illegal. Likewise for your class.

    // operator for allocating nbytes from default arena
    void* operator new(size_t s, size_t nybtes);

This is used as "pfMemory* m = new (0) pfMemory;" to allocate a pfMemory object
in pfGetSharedArena() with zero additional bytes. This operator new matches the
intent of your previous example.

    // operator for allocating nbytes from specific arena
    void* operator new(size_t s, size_t nbytes, void *arena);

This is the same as the previous except that you can also specify the arena.
For example "pfMemory* m = new (0, pfGetSharedArena()) pfMemory;" is equivalent
to the previous example.

> Is this valid? It looks like a good idea to me.

It provides some well defined behavior for you classes wrt to Performer's
environment. However you cannot create objects on the stack or in arrays. Also
the syntax is somewhat nonintuitive to avoid conflicts with placement new and
because pfMemory provides memory buffer services. It's an object plus raw
memory. In a sense pfMemory is "placement new" and RTTI encapsulated as a
class.

Regards.

--
+ Marcus Barnes, Technical Staff        mailto:marcus++at++multigen.com +
+ Multigen Inc.                         http://www.multigen.com    +
+ 550 S. Winchester Blvd.               phoneto:1-408-556-2654     +
+ Suite 500 San Jose CA 95128           faxto:1-408-261-4102       +
=======================================================================
List Archives, FAQ, FTP:  http://www.sgi.com/Technology/Performer/
            Submissions:  info-performer++at++sgi.com
        Admin. requests:  info-performer-request++at++sgi.com

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:55:05 PDT

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