LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-28-2009, 03:46 PM   #1
fryguy
LQ Newbie
 
Registered: Jun 2009
Posts: 3

Rep: Reputation: 0
C - Data structure shared among processes


Hi.

I have a rather advanced question in Linux C programming.

I'm writing some code for a library. This library loads a data structure from disk, and I need to keep it in memory as long as there are processes using it. The library has init and uninit functions, so that could serve for reference counting, and when the last process stops using it, the library can unload the data structure from memory.
My main problem is that the library is used from various processes, and all of them must share the same copy of the data structure.

I've looked at shared memory, but I would like to re-use some implementation of the data structure (hash table), like for example the GLib one, but those allocate on the heap, and AFAIK they can't be changed to allocate in the shared memory segment.
 
Old 06-28-2009, 04:30 PM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
If your data structures are on the heap, they are private, and cannot be shared. I do not think you will be able to use your present approach. Perhaps your objective can be accomplished using threads instead of multiple processes. Using shared memory also requires the use of mutex semaphores to prevent clashes when more than one process tries to write to the shared memory segment. Simply coercing an existing library to use a shared memory segment would also require it to use this or some other type of synchronization method.
--- rod.
 
  


Reply

Tags
ipc, linux



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shared data in shared libraries arvind.ayyangar Programming 7 10-23-2008 03:53 PM
A data structure problem Asuralm Programming 1 12-24-2007 07:49 AM
c++ data structure libraries kpachopoulos Programming 2 01-16-2007 04:22 PM
Data structure trie spank Programming 7 05-21-2006 07:21 AM
shared memory between two processes davidtexs3 Linux - Software 1 11-25-2005 02:25 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration