Re: Performer and C++

New Message Reply Date view Thread view Subject view Author view

Swaminathan N. (swami++at++evl.uic.edu)
Wed, 16 Apr 1997 18:04:17 -0500 (CDT)


On Wed, 16 Apr 1997, Steve Baker wrote:
>
> Jan Barglowski <jan++at++euryale.chinalake.navy.mil> replied:
>
> > Here's what I've done:
> > myClass *myClassPtr;
> > myClassPtr = (myClass *) pfMalloc(sizeof(myClass), pfGetSharedArena());
>
> Aaaaarrrggghhhh!
>
> Please don't do that - it bypasses the class constructor function - and
> for most classes, that will be a disaster!

If you include <new.h> and a reasonably upto date compiler you could do
placement new like

myClassPtr = new (pfMalloc(sizeof(myClass), pfGetSharedArena())) myClass;

You could also do the same by providing a second version of operator new like
this
void *
operator new(size_t s, void *v) {
  return v;
}
which allows you to do the above too. Note that this is different from the
Performer overloading of new, viz.
pfMaterial *mtl = new (pfGetSharedArena()) pfMaterial;

Placement new also helps get around the problem of not being able to overload
operator new []

Swami

 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
v Swaminathan Narayanan ^
v swami++at++evl.uic.edu ^
v Office: 996-3002 ^
v Home: 850-2726 ^
v http://www.evl.uic.edu/swami ^
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

=======================================================================
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.