From: Ani on 5 Jul 2010 01:52 Hi, I have a shared library with a global structure to store status and some other information. The problem is a every process trying to access this library gets a local copy of this structure. Is it possible to have only a single instance of this structure, irrespective of the number of processes accessing this library, so that I can share the data ? Is there a linker option or any other away through which I can achieve this ? I cannot do away with this structure and neither can I have a FS based solution as the reads are writes to this structure are frequent (using a flash storage). Looking for some ideas/advice on how to handle this. Thank you, Anirudh
From: Nicolas George on 5 Jul 2010 04:14 Ani wrote in message <41821d05-74a9-4ca1-8062-a29e8b0146c1(a)m37g2000prc.googlegroups.com>: > I have a shared library with a global structure to store status and > some other information. The problem is a every process trying to > access this library gets a local copy of this structure. Is it > possible to have only a single instance of this structure, > irrespective of the number of processes accessing this library, so > that I can share the data ? Is there a linker option or any other away > through which I can achieve this ? There is nothing simple. > I cannot do away with this structure and neither can I have a FS based > solution as the reads are writes to this structure are frequent (using > a flash storage). You could use a shared memory segment, or a server and remote procedure calls.
From: Rainer Weikusat on 5 Jul 2010 07:36 Ani <anirudhghayal(a)gmail.com> writes: > > I have a shared library with a global structure to store status and > some other information. The problem is a every process trying to > access this library gets a local copy of this structure. Is it > possible to have only a single instance of this structure, > irrespective of the number of processes accessing this library, so > that I can share the data ? Sure. You'll need to use some form of shared memory for that (SysV shm, shm_open & friends, mmaped files w/ well known names).
From: mac on 6 Jul 2010 18:37 > Is it > possible to have only a single instance of this structure, > irrespective of the number of processes accessing this library, so > that I can share the data ? Is there a linker option or any other away > through which I can achieve this ? There's no simple equivalent to a DLL with shared data. > I cannot do away with this structure and neither can I have a FS based > solution as the reads are writes to this structure are frequent (using > a flash storage). What I think you mean is that you can't have a disk-based solution. Files are just a way of naming common data, which is what you have here. It's true that you could use sysV shared memory, which has its own name scheme, but I've always found shared mmap easier to work with. You also have to consider locking. I also use flock instead of sysV semaphores. Depending on where you put a file, it can be accessed in-memory. If it never gets sync'd, it can be deleted withiut ever going to disk. Some Unices (Solaris?) even have temp filesystems that are purely RAM. -- mac the naïf
From: Gordon Burditt on 7 Jul 2010 15:14
>I have a shared library with a global structure to store status and >some other information. The problem is a every process trying to >access this library gets a local copy of this structure. Is it >possible to have only a single instance of this structure, >irrespective of the number of processes accessing this library, so >that I can share the data ? Is there a linker option or any other away >through which I can achieve this ? You need to be aware of many problems with this, including the possibility that accessing the single instance on someone else's machine without permission may be considered an act of war, or worse, carry a very VERY large pay-per-byte access fee. The closest thing I can think of is changing the global structure to a global (but accessed by one process) pointer to the structure, initialized by a call to mmap() or shmat() to attach a shared memory segment. Somehow you need to deal with the situation that if nobody has that segment open, one (and only one) process needs to initialize it. |