Re: pfMemory clarification

New Message Reply Date view Thread view Subject view Author view

Swaminathan N. (swami++at++evl.uic.edu)
Fri, 18 Apr 1997 21:31:41 -0500 (CDT)


On Fri, 18 Apr 1997, Marcus Barnes wrote:

> to allocate the array, BUT ... :
>
> pfMemory* mem = new ( 20 * sizeof(pfVec3) ) pfMemory;
> pfVec3* sidecoords = new ( mem ) pfVec3[ 20 ]; // placement ::operator new[]()
>
> ... even if this does work you _cannot_ use it! This is because Performer
> whould never know to call "delete [] sidecoords". Therefore
> pfMemory::checkDelete( sidecoords ) is an error and yet that is what must work
> in order to support arrays in Performer. The lesson is "if you cannot properly
> destroy each element of an array then you shouldn't create such an array."

What I've done (within the limitations of the 6.x compiler) to allocate and
destroy arrays of objects in shared memory is this...

  // to allocate values[num]
  object *values = new (pfMemory::malloc(sizeof(object)*num, arena)) object[num];
  // to delete the above
  for (int i=0; i<num; i++)
    values[i].~object();
  pfMemory::free(values);

yucky, but I don't know of any other way of ensuring arrays of constructed
objects in shared memory.

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