From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <96078721911868.tru64-unix-managers.marc@archive.invalid> From: Nicolas St-Laurent Date: Wed, 16 Sep 1998 12:06:56 +0000 To: tru64-unix-managers Subject: SUMMARY Shared library and global variables X-MARC-Message: https://marc.info/?l=tru64-unix-managers&m=96078721911868 In message , 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@zk3.dec.com Digital's Easynet: alpha::tpb ACM Member: tpblinn@acm.org PC@Home: tom@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@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 --------------