Re: re-sharing memory
From: Shawn D Fox (shawn.fox_at_digwiz.com)
Date: 02/24/05
- Next message: Ajay Kalra: "Re: export functions from MFC extension DLL"
- Previous message: andrew: "Re: WebBrowser control"
- In reply to: Steph Sharp: "re-sharing memory"
- Messages sorted by: [ date ] [ thread ]
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
- Next message: Ajay Kalra: "Re: export functions from MFC extension DLL"
- Previous message: andrew: "Re: WebBrowser control"
- In reply to: Steph Sharp: "re-sharing memory"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|