Data structures in a shared library being accessed by multip

Hi all,

Hi all,

Forgive my ignorance but… I have a question regarding the use of shared
libaries and the data structures that they hold.

I want to have a shared library that encapsulates and manages a set of data
structures. These data structures are important to a number of applications
on the system. That is, I want to access these structures through the
functions of the library (get/set style) but I want the data to be shared
amongst the several applications.

I know I can do this by having the libary map an area of memory into a
processes space. What I want to know is if there is a way of simply keeping
a set of static structures as part of the shared library that we can then
access from several applications (assuming appropriate mutexes and such).

Any ideas? Thanks in advance.

Rich

Rich Wilkie <rwilkie@nortelnetworks.com> wrote:

Hi all,

Forgive my ignorance but… I have a question regarding the use of shared
libaries and the data structures that they hold.

I want to have a shared library that encapsulates and manages a set of data
structures. These data structures are important to a number of applications
on the system. That is, I want to access these structures through the
functions of the library (get/set style) but I want the data to be shared
amongst the several applications.

I know I can do this by having the libary map an area of memory into a
processes space. What I want to know is if there is a way of simply keeping
a set of static structures as part of the shared library that we can then
access from several applications (assuming appropriate mutexes and such).

Any ideas? Thanks in advance.

My understanding is that you can’t do this. That you have to go with
the explicit mmap() to do shared memory between processes.

Think of it as being the case that you will could have a libyourlib.so
and a libyourlib.a and they will both give you the same behaviour.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

You’re going to have to setup some sort of shared memory between
processes.

Check out the shm_open documentation for an example. You may also
need to use a mutex to protect access to the data structures.

Another way to do it (and better if you want network transparency)
is to have a server broker requests to the data. You might make
a resmgr that manages it, for example it might register

/dev/shared_data_broker/data_item_one
/data_item_two
/data_item_three

The clients would then do an open/read/write/close on the shared
data.

The two approaches have different benefits and tradeoffs. As long
as you don’t need to share data across different nodes, then the
shared memory one is probably easier to implement and has better
performance.

Rich Wilkie <rwilkie@nortelnetworks.com> wrote:

Hi all,

Hi all,

Forgive my ignorance but… I have a question regarding the use of shared
libaries and the data structures that they hold.

I want to have a shared library that encapsulates and manages a set of data
structures. These data structures are important to a number of applications
on the system. That is, I want to access these structures through the
functions of the library (get/set style) but I want the data to be shared
amongst the several applications.

I know I can do this by having the libary map an area of memory into a
processes space. What I want to know is if there is a way of simply keeping
a set of static structures as part of the shared library that we can then
access from several applications (assuming appropriate mutexes and such).

Any ideas? Thanks in advance.

Rich


cburgess@qnx.com

Yes, this sounds like the perfect application of shared memory. Why do you
feel it needs to be a shared library?

“Rich Wilkie” <rwilkie@NortelNetworks.com> wrote in message
news:aamjpg$bqh$1@inn.qnx.com

Hi all,

Hi all,

Forgive my ignorance but… I have a question regarding the use of shared
libaries and the data structures that they hold.

I want to have a shared library that encapsulates and manages a set of
data
structures. These data structures are important to a number of
applications
on the system. That is, I want to access these structures through the
functions of the library (get/set style) but I want the data to be shared
amongst the several applications.

I know I can do this by having the libary map an area of memory into a
processes space. What I want to know is if there is a way of simply
keeping
a set of static structures as part of the shared library that we can then
access from several applications (assuming appropriate mutexes and such).

Any ideas? Thanks in advance.

Rich