It is currently Sat, 04 Feb 2023 13:15:45 GMT



 
Author Message
 Singleton global variable in a shared library
Hi

I was wondering how you can specify that a global variable instance in a
shared
library should be shared among all clients of that library - i.e. clients
should share
the same instance. (Similar to a singleton).

In win32, this is achieved using a pragma like so:

#pragma data_seg(".SHARED")
std::string g_myGlobalString;
#pragma data_seg()

On Solaris, I use the GNU g++ compiler version 3.01

Anyone?

Regards
Martin



 Mon, 19 Apr 2004 18:33:07 GMT   
 Singleton global variable in a shared library
[ mart...@online.no ]
|
| Hi
|
| I was wondering how you can specify that a global variable instance in a
| shared
| library should be shared among all clients of that library - i.e. clients
| should share
| the same instance. (Similar to a singleton).
|
| In win32, this is achieved using a pragma like so:
|
| #pragma data_seg(".SHARED")
| std::string g_myGlobalString;
| #pragma data_seg()
|
| On Solaris, I use the GNU g++ compiler version 3.01
|

I _think_ you need to use shared memory (see man shm_open), and protect
the access to it (mutex/lock/...)

Trond



 Sat, 24 Apr 2004 00:45:49 GMT   
 
   [ 2 post ] 

Similar Threads

1. global variable with shared library

2. Global variables inside shared library on Solaris

3. Visibility of global variables in shared libraries

4. Shared libraries and global variables

5. global variable in shared library?

6. global variable in shared library.

7. Problems with shared libraries and external global variables

8. Global data sharing in shared libraries

9. Shared variable between main() and loaded shared library - dlopen()

10. shared variables in shared libraries


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software