Re: C++/memory allocation

New Message Reply Date view Thread view Subject view Author view

Nicolas Gauvin (nicolas++at++cae.ca)
Thu, 15 Aug 1996 14:31:01 -0400


On Aug 15, 10:18am, wasileskib++at++adadv1.mdc.com wrote:
> Subject: C++/memory allocation
>
> myptr = (mytype *)pfMalloc(sizeof(mytype), pfGetSharedArena());
>
> For the variables within 'mytype' which are not
> automatically created from shared memory, like pfChannels,

pfChannels are always allocated from shared memory, like most (if not all)
classes that are part of libpf.

> since 'myptr' is allocated from the arena, as in
> the statement above, does this imply that all the
> elements within 'myptr' which I construct with the
> "new" operator will allocate memory from the arena as
> opposed to the heap?

The fact that 'myptr' is allocated from the arena does
not imply that the elements within 'myptr' will be
allocated from shared memory via new.

However most pfClasses overrides locally the new operator to
use the default shared arena (not the heap). So if all elements
of 'myptr' are pfClasses, they will be in shared memomy.

new pfClass = default shared arena allocation (same a pfGetSharedArena());
new(arena) pfClass = specified shared arena allocation
new(NULL) pfClass = heap allocation

If you want your own class to have this same behavior

you can:

1) derive your class from pfObject

or

2) if you don't need all the things that comes with pfObject you can use the
PFSTRUCT_DECLARE macro defined in pfStruct.h in the following manner:

  class yourClass {
    PFSTRUCT_DECLARE
  };

Performer 2.0 doesn't override the global new operator.

-- 
Nicolas Gauvin			CAE Electronics Ltd., 8585 Cote De Liesse
Software Developer 		Saint-Laurent, Quebec, Canada, H4L-4X4
3-D Graphics Applications	tel: +1 514 341 2000 extension 2275
nicolas++at++cae.ca			fax: +1 514 340 5496
=======================================================================
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:53:22 PDT

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