
Using a shared lib as shared memory: Possible?
The question I'm about to ask was asked on comp.unix.programmer some time
back, in a slightly different context, by sort of a newbie type - who didn't
really understand what a shared lib is - but the thing is, I can't quite
remember what the outcome/resolution of that thread was. So, I'm going to
ask it again...
My assumption is that if a shared lib is pure code, then all of the
currently running applications which are using that lib, are using the same
copy of it - i.e., that it is allocated space in (global/system-wide) memory
and everybody runs the same code when calling functions in the lib.
However, if there is static data in the lib, then a fresh copy of the static
data gets allocated for each caller. And this is as it should be, since
otherwise, there would be chaos.
However, my question is, is it possible, through some compiler or linker
switches (or any other settings), to override this - to make a lib such that
when one program changes a global/static variable in the lib, the other
programs see the change?
Platform is Solaris, although I'd like the solution to also be portable to
Linux (although this isn't critical). Objective is simply convenience/not
having to mess around with shared memory or mmap(). I view this as a Q&D
way of getting shared memory.