how to have a shared variable in library across all application in linux (c++)?
views:
78answers:
2
+3
A:
You can use POSIX shared memory to create a shared memory segment, and place the variable there. You will need to synchronise access to the shared variable using POSIX semaphores.
See the shm_overview(7) and sem_overview(7) man pages to get started.
caf
2009-12-21 04:53:52
A:
Likewise, you can use posix shared memory or just mmap() a file and have the variable exist in that area of memory.
The loader will not automatically do this with a special section such as the "shared" one in Win32 DLLs. This is probably not a big deal as it's a bit of an anti-feature anyway.
MarkR
2009-12-21 10:18:59