From: Dan Johnston (dan.johnston++at++nrc.ca)
Date: 12/14/2001 11:20:09
Still working with pfDataPool...
The attached C++ code snippet is supposed to check for
the existance of a shared memory file, and skip out
if it exists.
What I get;
The temporary file does NOT esist
The value of 'shared' after the 'attach' is NULL
We go on to create the data pool (and file) and
allocate block of memory in it to store stuff.
(run the code again)
the temporary file DOES exist
the value of 'shared' after the attach is still NULL
We re-create the data pool and file
...
What is the silly thing that I'm doing wrong?
The C-language code found in
/usr/share/Performer/src/lib/libpfutil/shmem.c
supposedly works, and I thought I used the
same logic.
Thank for your help!
Dan
--
___|__ |
/ | \ ||\ Daniel (Dan) Johnston
/___|___\ || \ Dan.Johnston++at++nrc.ca
_____|____ || \ National Research Council of Canada, London, ON
| | | || \ Integrated Manufacturing Technologies Institute
\___| | | ||____\ Tel: (519) 430-7081 Fax: (519) 430-7090
\_o_\___|____|_|______\_ Inst: http://www.nrc.ca/imti
\ o / These opinions are my own! Not those of NRC.
\________________/ Virtual Reality:
http://www.nrc.ca/imti/vetc/home.html
More Tall Ships - Fewer Computers!
// // write_2poly.C: create a simple 2 triangle poly and save // in shared memory for another process to draw. // // $Revision: 1.10 $ // $Date: 2000/10/06 21:26:42 $ // //
#include <Performer/pr/pfGeoSet.h> #include <Performer/pr/pfDataPool.h> #include <Performer/pr/pfGeoState.h> #include <iostream.h>
#define PROGRAM "write_2poly" #define MEM_FILE "dpoolForSharedData"
static long DPoolSize = 1 << 17; /* 128K bytes */
int main (void) { // Initialize Performer pfInit();
// try to attach to an existing shared memory data pool pfDataPool *shared = pfDataPool::attach(MEM_FILE); if ( shared != NULL ) { cerr << PROGRAM << "create error;" << MEM_FILE << "already exists\n"; exit(1); }
// create the shared memory data pool if ( (shared = pfDataPool::create(DPoolSize,MEM_FILE)) == NULL ) { cerr << PROGRAM << " unable to open" << MEM_FILE << "for data pool\n"; exit(1); }
// Set up a geoset with 5 parts - vertex, index, colors, gset, gstate pfVec3 *coords = (pfVec3 *)shared->alloc(4*sizeof(pfVec3), 101); coords[0].set(-1.0f, -1.0f, 0.0f ); coords[1].set( 1.0f, -1.0f, 0.0f ); coords[2].set( 1.0f, 1.0f, 0.0f ); coords[3].set(-1.0f, 1.0f, 0.0f );
// dummy index for now ushort *index = (ushort *)shared->alloc(12*sizeof(ushort), 102);
pfVec4 *colors = (pfVec4 *)shared->alloc(4*sizeof(pfVec4), 103); colors[0].set(1.0f, 1.0f, 1.0f, 1.0f); colors[1].set(0.0f, 0.0f, 1.0f, 1.0f); colors[2].set(1.0f, 0.0f, 0.0f, 1.0f); colors[3].set(0.0f, 1.0f, 0.0f, 1.0f);
pfGeoSet *gset = (pfGeoSet *)shared->alloc(sizeof(pfGeoSet), 100); pfGeoSet *temp = new pfGeoSet(); pfMemory::copy(temp,gset); delete temp; gset->setAttr(PFGS_COORD3, PFGS_PER_VERTEX, coords, NULL); gset->setAttr(PFGS_COLOR4, PFGS_PER_VERTEX, colors, NULL); gset->setPrimType(PFGS_QUADS); gset->setNumPrims(1);
// Set up a geostate, backface removal turned off pfGeoState *gstate = (pfGeoState *)shared->alloc(sizeof(pfGeoState), 104); pfGeoState *temp2 = new pfGeoState(); pfMemory::copy(temp,gstate); delete temp2; gstate->setMode(PFSTATE_CULLFACE, PFCF_OFF); gset->setGState(gstate);
// the GeoSet is now stored in shared memory // do NOT delete it, i.e. it will be cleaned by the // drawing process }
This archive was generated by hypermail 2b29 : Fri Dec 14 2001 - 11:27:02 PST