From: George on
Hello everyone,


If we define global variable and static variable of a class, which are
implemented in a DLL. My questions are,

1. All instances of class share the single copy of global variable and
static variable of class? If yes, I need to have some synchronization
approach on them.

2. Is it safe to use global variable and static (public) variable after DLL
unloads?


thanks in advance,
George
From: Igor Tandetnik on
"George" <George(a)discussions.microsoft.com> wrote in message
news:11065AB0-209E-42F6-9ABD-8A9E742B5616(a)microsoft.com
> If we define global variable and static variable of a class, which are
> implemented in a DLL. My questions are,
>
> 1. All instances of class share the single copy of global variable and
> static variable of class?

Yes.

> If yes, I need to have some synchronization
> approach on them.

Probably.

> 2. Is it safe to use global variable and static (public) variable
> after DLL unloads?

Of course not.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


From: George on
Thanks Igor,


1.

> > If yes, I need to have some synchronization
> > approach on them.
>
> Probably.

Why probably? If such variables can be accessed by multiple threads, we have
to synchronize them, right? Any exceptions?

2.

Whether it is possible to load a DLL twice inside a process? If yes, whether
in this case, there is multiple copies of global variable and static variable
of a class?


regards,
George
From: Igor Tandetnik on
"George" <George(a)discussions.microsoft.com> wrote in message
news:3D7B4B45-27E8-4314-AC96-E42589B8BCC6(a)microsoft.com
>>> If yes, I need to have some synchronization
>>> approach on them.
>>
>> Probably.
>
> Why probably?

Well, if you document that the class cannot be used in a multithreaded
manner, then you don't need to synchronize. Or perhaps you initialize
the variable when DLL loads, and never modify it after that.

Without knowing the intended usage, I can't be sure you absolutely need
to synchronize. Hence "probably".

> Whether it is possible to load a DLL twice inside a process?

No.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


From: George on
Thanks Igor,


> > Whether it is possible to load a DLL twice inside a process?
>
> No.

If we call LoadLibrary multiple times, there is still one copy of (data --
like global variable and static member veriable of class) of DLL?


regards,
George