Re: Performer Memory Question

New Message Reply Date view Thread view Subject view Author view

Timothy Moore (moore++at++WOLFENET.com)
Mon, 28 Apr 1997 12:08:21 -0700 (PDT)


   From: "Steven Lovelady" <stevenl++at++skopen.dseg.ti.com>
   Date: Mon, 28 Apr 1997 07:06:18 +0000

   Howdy folks,

   I have a question about the memory allocation in Performer. Do
   these two methods of memory allocation give you the same result in
   Performer?

No. You won't even be able to compile the first method in C.

   Method 1:
   ------------------------

   typedef struct {
       pfVec3 xyz;
       pfVec3 hpr;
       pfGeoState gstate;
       } BOGUS;

   BOGUS bog = pfMalloc( sizeof(BOGUS), pfGetSharedArena() );

   Method 2:
   ------------------------

   typedef struct {
       pfVec3 *xyz;
       pfVec3 *hpr;
       pfGeoState *gstate;
       } BOGUS;

   BOGUS bog = pfMalloc( sizeof(BOGUS), pfGetSharedArena() );
   bog->xyz = pfMalloc( sizeof(pfVec3), pfGetSharedArena() );
   bog->hpr = pfMalloc( sizeof(pfVec3), pfGetSharedArena() );
   bog->gstate = pfNewGState(pfGetSharedArena());

   I am asking for two reasons. First, if I use Method #1 will all of
   the processes be able to see all of the members of the structure?
   Second, does the pfNewGState function do anything special to allocate
   the memory for the GeoState or will it be ok if it is allocated as
   part of the structure?

All processes will be able to see the memory allocated with method 1.
However, you should never try to declare Performer structures that are
derived from pfObject in your own code; declare pointers to them and
call the pfNew* functions. pfVec3 are very simple and aren't derived
from pfObject, but pfGeoState is not simple. pfNewGState does in fact
do a lot of special initialization.

A 3rd method that is slightly more efficient than Method 2 is:

typedef struct
{
  pfVec3 xyz;
  pfVec3 hpr;
  pfGeoState *gstate;
} BOGUS;

BOGUS bog = pfMalloc (sizeof (BOGUS), pfGetSharedArena ());
bog->gstate = pfNewGState (pfGetSharedArena ());

Tim
=======================================================================
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:07 PDT

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