LinuxQuestions.org
Register a domain and help support LQ
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
 
LinkBack 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
Senior Member
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 4,506

Rep: Reputation: 602Reputation: 602Reputation: 602Reputation: 602Reputation: 602Reputation: 602
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are 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 nocturna_gr 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


All times are GMT -5. The time now is 03:06 PM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration