Re: More Semi off Topic: SHMEM

New Message Reply Date view Thread view Subject view Author view

Pete Willemsen (willemsn++at++cs.uiowa.edu)
Wed, 23 Jun 1999 21:53:13 -0500


Hi.

We used something like this in a simulator we developed.

For a quick summary, we basically overloaded the "new" and "delete"
operators in a special class that we called SharedMemoryObject. Any C++
class that we needed to share between processes was derived from the
SharedMemoryObject class. The SharedMemoryObject class used our own
shared memory allocation scheme (using SYSV shared memory) to allocate
chunks of memory from a shared memory segment.

There are a few tricky issues to deal with when you do something like
this.

1) The shared memory that we created had to be directly mapped into each
process in exactly the same virtual address space. This is necessary,
especially if you use virtual functions because the virtual table and
related pointers within will point to areas in shared memory. If this
is not done, access to virtual member functions can cause strange
segmentation violations that (in some cases) can be hard to debug. This
can be tricky when using programs that link with things of different
sizes. I came up with a "pre-run" test that would tell me what address
locations were available to use and then I took the largest of these and
used that as an argument to the simulator.

2) If a shared memory object allocates objects of its own, those objects
will probably need to be made shared memory objects so the data and
virtual pointers are still accessible.

3) This may not be portable to all systems, although we successfully ran
this simulator on IRIX and Linux based systems.

If you (or anyone else) is interested in more detail about this, I'll
gladly send some code and more explanation, if necessary.

Pete

"Arnott, Shane D" wrote:
>
> Hi,
>
> I'm trying to find a nice way to share memory between two unrelated (read no
> fork no sproc etc) processes.
>
> I have a Java UI front end that has a C++ layer underneath through JNI which
> I want to talk to my C++ Vega/Performer app.
>
> The vgMem functions only help with related processes, so they are out.
>
> I've looked at pfDataPool but that doesn't seem suited to C++ with the only
> memory allocation call being:
>
> vol void * pfDataPool::alloc(size_t...)
>
> It seems I have no way of doing a new on my C++ objects for both processes
> to share.
>
> Does anybody have any other ways of cleanly sharing memory across unrelated
> processes, especially one suited for C++.
>
> Thanks in advance.
> ___________
> Shane Arnott
> Boeing Australia Limited * 363 Adelaide St * Brisbane * QLD 4000
> Communications & Battle Management Systems * Systems Analysis Lab
> Email: Shane.D.Arnott++at++Boeing.com * Ph: +61 7 3306 3320
>
> -----------------------------------------------------------------------
> List Archives, FAQ, FTP: http://www.sgi.com/software/performer/
> Submissions: info-performer++at++sgi.com
> Admin. requests: info-performer-request++at++sgi.com

-- 

Pete ---------------------------------------------- Pete Willemsen Department of Comp. Sci. willemsn++at++cs.uiowa.edu University of Iowa ----------------------------------------------


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Wed Jun 23 1999 - 20:04:45 PDT

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