pfMalloc & object container

New Message Reply Date view Thread view Subject view Author view

Jay Gischer (gischer++at++puget.engr.sgi.com)
Tue, 28 Apr 1998 09:05:55 -0700 (PDT)


David Chan writes:
> HI,
> I have a problem with pfMalloc when I am using pfMalloc to create
> a shared memory. Here is my simple code:
>
> shared=(SharedData *)pfMalloc(sizeof(SharedData),
> pfGetSharedArena());
>
> while SharedData is a typedef structure, and inside SharedData, there is a
> Class container:
>
> typedef structure {
> ....
> Console *console[10];
> ....
> } SharedData;
>
> Where Class "Console" is an abstract class, the array is to store derived
> class from "Console".
> I can create an object and assign it into the array, but after
> that, when I want to access the object's public function like this:
>
> shared->console[0]->
>
> It is always segmentation falut.

I don't think that pointers work too well with shared memory here.
If the Console's were allocated from shared memory, their addresses
will possibly change from process to process. If they weren't the
memory won't even be there in a different process.

If in fact the Console structures are to be shared, it would be better
to do:

   typedef structure {
           ...
           Console console[10];
           ...
   } SharedData;

   and then

   SharedData *sd = (SharedData *)pfMalloc(sizeof(SharedData),pfGetSharedArena);
   sd->console[0] = *new Console(whatever);

// This way the console data is sure to be in shared memory too.
// There are other ways to cope with this

> I am using "CC" to compile and "cc" to link the object programs on IRIX
> 6.2 Indy.
>

If it were me, I'd try to use "CC" to link as well. I don't know if it's the
cause of any of your problems.

-j
=======================================================================
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:57:18 PDT

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