SUMMARY Shared library and global variables

From: Nicolas St-Laurent <Nstlaurent_at_DGEQ.QC.CA>
Date: Wed, 16 Sep 1998 08:06:56 -0400

In message <s5fe8c43.008_at_DGEQ.QC.CA>, Nicolas St-Laurent writes:
>
> Hello,
>
> we got a lot of statics libraries and we're looking to convert
> them
> in shared libraries. There's just got one big problem : the static librairie
> s
> we use defines lot of global variables (yes, I know it's awful but that's
> life...). How the global variables are used by the shared libraries ? It's
> there one variable for each program using the library or there's just one
> variable for the library and all the programs used the same ?
>

Global variables are mapped into the process' address space. So by
modifying
one global variable, you don't affect another app's global variable.

If you need a mechanism to share global variables, then you need to
look into IPC and shared memory ... Which is an entirely different
ballpark.

--Stephan


The global variables are allocated on a "per executing instance" basis;
they
are not present in the libraries themselves, but rather are allocated in the
executable image that's linked against the library.

There are ways to share memory between executing programs, but the
presence
of global variables in shared libraries doesn't make that happen, for
reasons that should be really obvious once you think about it.

Tom
 
 Dr. Thomas P. Blinn + UNIX Software Group + Compaq Computer
Corporation
  110 Spit Brook Road, MS ZKO3-2/U20 Nashua, New Hampshire
03062-2698
   Technology Partnership Engineering Phone: (603) 884-0646
    Internet: tpb_at_zk3.dec.com Digital's Easynet: alpha::tpb
     ACM Member: tpblinn_at_acm.org PC_at_Home: tom_at_felines.mv.net

Hello,

First of all, I agree that you should remove as many globals as possible.
But then you really don't need to worry about them when using shared
libs.
You translate the static lib into a shared lib (this is often only a
one-liner on alpha), and that's is. Each program will keep its own
copy of its variables. Be it global or not.

Greetings,

Bert.

-------------- eMail Bert.Deknuydt_at_esat.kuleuven.ac.be ---------------
B.DeKnuydt, PSI-KULeuven Tel. +32-16-321880
K. Mercierlaan 94 /| | ||
B-3001 Heverlee Leuven _,_)| 4_|_||
FLANDERS, BELGIUM / . Fax. +32-16-321986
-------------- http://www.esat.kuleuven.ac.be/~deknuydt --------------
Received on Wed Sep 16 1998 - 12:05:56 NZST

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:38 NZDT