Re: re-sharing memory

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Shawn D Fox (shawn.fox_at_digwiz.com)
Date: 02/24/05


Date: Wed, 23 Feb 2005 16:35:03 -0800

I've had a problem like this before. Our problem had to do with structural
byte alignment settings for projects. Here was a description of our
problem. Maybe you are seeing something similar.

We would dynamically instantiate a global data structure in our main
project. This data structure was how we allowed threads to communicate with
each other. The pointer would be written to a global pointer within another
"mediator" dll, where we store pointers to global objects or implement
utility functions useful for all of our dlls. Since the GUI is in our main
project, the user might enter data into a dialogue. The dialogue saves the
data to global memory, that will be read by another DLL (perhaps something
that deals with TCP/IP configuration for instance). Then the other DLLs
would read the data, using this global pointer. After seeing some ugly
problems our debugger showed that the value of the structure members in 1
dll looked completely different than the structure in other DLLs even though
they were all accessing the same pointer to the same data structure.

Under my configuration properties of the visual studio projects, look at
C/C++ -> code generation -> Struct Member Alignment.

We had some projects set to 1 byte and others set to 8 bytes or default or
some other value. We found that different dlls would would access a shared
resource and see the data differently. We had to make sure that our DLLs
and projects, within the application, all had the same struct member
alignment setting. Note that there was no file sharing here. We are simply
talking about dynamically allocated memory for a class or structure that is
shared between different modules but within the same application and .exe
process.

Maybe that is similar to what you are seeing. By process, I don't know if
you mean different programs or different modules within a program.

Best Regards,
Shawn

We had an MFC application with a project and multiple MFC extension DLLs.
"Steph Sharp" <sm_sharp@lycos.co.uk> wrote in message
news:17730349.0502220849.63d9aeb5@posting.google.com...
>I am experiencing a problem where the data in a structure in shared
> memory is not being preserved.
>
> Process A creates the shared memory, spawns and passes the name to
> process B
> Process B opens and initialises the shared memory.
> All comunications between processes A and B work as expected.
> Process B then spawns another process (C) and passes it the name of
> the same shared memory.
> When Process C attempts to read an integer value in the shared memory,
> I am finding it to be set to a random large number, and not the value
> set by Process B.
>
> Note that I did not write Process A, nor design the structure used to
> share memory, I simply want to read and write values in processes B
> and C.
>
> Does anyone know what can cause this behaviour and how to prevent it?
>
> I am using VS.Net 7.1 WinXP.
>
> Thanks in advance,
> Steph



Relevant Pages

  • Re: essential OS/2
    ... That entirely defeats the point of DLLs in the first place and has an enormous impact on shared memory usage, and God knows things are tight enough in that department already these days. ... The whole point and main difference between OS/2 and Linux has been the fact that programs come complete on OS/2 and not so on Linux. ...
    (comp.os.os2.misc)
  • Re: Share data between different dlls
    ... What about Win32 shared memory? ... Seems like your dlls are behaving like out ... I've tried to create a global class object of CData*, ... > pData, by declaring it as an external in the header and initiate it in the ...
    (microsoft.public.dotnet.languages.vc)
  • Re: shared memory malloc library
    ... you need to do all pointer operations in the heap code relative to the ... base adresse which you get when you map in the shared memory. ... just providing an additional parameter to *malloc() and kin. ...
    (comp.lang.c)
  • Re: copying structures in shared memory
    ...     int x ... wise since the term "shared memory" only makes sense when there ... in the process this pointer is coming from. ...
    (comp.lang.c)
  • Re: Garbage Collection in C
    ... since if the number of DLLs that the ... casting an object pointer to a pointer with a less strict alignment ... the result of converting a pointer ...
    (comp.lang.c)