Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Sharing global data using #pragma data_seg directive

456 views
Skip to first unread message

John C. Liss

unread,
Aug 2, 1999, 3:00:00 AM8/2/99
to
I'm trying to share a variable located in a shared DLL but when
accessing
from two different processes they both appear to maintain there own
memory locations. The shared data segment shows up when using
"QuickView", if I omit either the linker command ("/SECTION:.shared,RWS
")
or the "C" file directive,
#pragma data_seg(".shared")
int nNumInQueue = 4;
int nWriteLocation = 0;
int nReadLocation = 0;
#pragma data_seg()

the shared segment is removed from the QuickView.

Is there any differences between C or C++?
Is there any possible project setting/command line directive which will
override
this pragma directive?

References KnowledgeBase :
"How to Share Data Between Different Mappings of a DLL" (Q125677).
"Specifying Shared and Nonshared Data in a DLL" (Q100634).
"How to Specify Shared and Nonshared Data in a DLL" (Q89817).
"Sharing All Data in a DLL" (Q109619).


Any help would be appreciated,
John


J. Wesley Cleveland

unread,
Aug 2, 1999, 3:00:00 AM8/2/99
to

"John C. Liss" wrote:
>
> I'm trying to share a variable located in a shared DLL but when
> accessing
> from two different processes they both appear to maintain there own

> memory locations. [snip]

Do you mean that the addresses are different or that the values of the
variables are different?
The addresses may well be different in different processes.

John C. Liss

unread,
Aug 3, 1999, 3:00:00 AM8/3/99
to
The actual values are different after incrementing in one process or the
other.
And yes the addresses are also different, this is why the values are
different
after either processes updates it. They do start at the same value
"int nNumInQueue = 4".

Looking at the KnowledgeBase articles I listed, it appears that sharing
variables in a DLL is very straight forward simply declaring the desired
shared variables within the shared data segment. And as I mentioned
the data segment does show up as shared, I guess for some reason the
variables I declared don't get included in this segment.

As a workaround I could use a file mapping solution but this shared
data segment would prove beneficial in this project and I'm sure others
in the future. And again, any thought are still appreciated!!

Thanks again,
John

J. Wesley Cleveland

unread,
Aug 3, 1999, 3:00:00 AM8/3/99
to

"John C. Liss" wrote:
>
> The actual values are different after incrementing in one process or the
> other.
> And yes the addresses are also different, this is why the values are
> different
> after either processes updates it. They do start at the same value
> "int nNumInQueue = 4".
>
> Looking at the KnowledgeBase articles I listed, it appears that sharing
> variables in a DLL is very straight forward simply declaring the desired
> shared variables within the shared data segment. And as I mentioned
> the data segment does show up as shared, I guess for some reason the
> variables I declared don't get included in this segment.
>
> As a workaround I could use a file mapping solution but this shared
> data segment would prove beneficial in this project and I'm sure others
> in the future. And again, any thought are still appreciated!!

One suggestion is to base your dll at some odd address to avoid
relocations. Neither softice or VC6 debugger is easy to use on dlls that
have different addresses in different process spaces

Alexander Bartolich

unread,
Aug 4, 1999, 3:00:00 AM8/4/99
to
> And yes the addresses are also different, this is why the values are
> different after either processes updates it.

DLL's are mapped in arbitrary order into the address space of a process.
This means the logical address of variables and functions can be
different
between two processes loading the same DLL.
The mapping of shared sections is done through the paging mechanism,
i.e.
on the layer of physical addresses.

0 new messages