Board index » delphi » global variables inside DLL

global variables inside DLL

If I define a variable inside the implementation part of a dll unit, is it
going to be available to the all applications that use that dll, or for
every application that loads this dll a new data *segment* will be created.

Thanks,
Smola

 

Re:global variables inside DLL


Global variables in DLL are global in current instance of DLL.
If 2 applications call DLL, they cannot share global variable as there
are 2 copies in 2 different memory spaces.

It can be done, but is a real pain.

Quote
On Mon, 9 Apr 2001 21:38:11 +0200, "Smola" <A...@inet.hr> wrote:
>If I define a variable inside the implementation part of a dll unit, is it
>going to be available to the all applications that use that dll, or for
>every application that loads this dll a new data *segment* will be created.

>Thanks,
>Smola

Regards,
E.Beli
http://www.greenhousemm.com

Re:global variables inside DLL


Correct .. and a very, very important difference in behavior from Windows 3.x!

In Windows 3.x, DLLs were globally mapped into every address-space that
loaded them.  Every variable owned by the DLL was therefore global.

In order to share values in a similar way in a DLL, the library must
expressly open a shared memory-segment or memory-mapped file.  Each
instance of the DLL must do this.

The internal architecture of the 16-bit Windows system and the 32-bit
system is -fundamentally- different, and the handling of DLLs is a good
example of it.

In article <3ad23b4b.64551...@news.terra.com.br>,

Quote
b...@SPAAMMgreenhousemm.com (Beli) wrote:
> Global variables in DLL are global in current instance of DLL.
> If 2 applications call DLL, they cannot share global variable as there
> are 2 copies in 2 different memory spaces.

> It can be done, but is a real pain.

> On Mon, 9 Apr 2001 21:38:11 +0200, "Smola" <A...@inet.hr> wrote:

> >If I define a variable inside the implementation part of a dll unit, is it
> >going to be available to the all applications that use that dll, or for
> >every application that loads this dll a new data *segment* will be created.

> >Thanks,
> >Smola

> Regards,
> E.Beli
> http://www.greenhousemm.com

Other Threads