For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > May 2004 > Linked List









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Linked List
Xarky

2004-05-22, 4:35 am

Hi,
I would like to implement a linked list in memory that is to be
shared between different processes. Is this possible, and how?


Thanks in Advance
Måns Rullgård

2004-05-22, 5:31 am

bernardpace@yahoo.com (Xarky) writes:

> Hi,
> I would like to implement a linked list in memory that is to be
> shared between different processes. Is this possible, and how?


Anything is possible. Use shared memory and make sure you do
sufficient locking.

--
Måns Rullgård
mru@kth.se
mikegw

2004-05-22, 11:37 am


"Xarky" <bernardpace@yahoo.com> wrote in message
news:bc42e1a.0405212359.134e49c1@posting.google.com...
> Hi,
> I would like to implement a linked list in memory that is to be
> shared between different processes. Is this possible, and how?
>
>
> Thanks in Advance


One way is SYSV. I think that it is kinda old and is not largely supported.
I am using it in linux across a few different processes/machines. Hope this
helps.

I found that an array of structures was better than a linked list as the
only way into the memory was a pointer to the header, everything was an
offset from this.

Mike


Barry Margolin

2004-05-22, 6:31 pm

In article <bc42e1a.0405212359.134e49c1@posting.google.com>,
bernardpace@yahoo.com (Xarky) wrote:

> Hi,
> I would like to implement a linked list in memory that is to be
> shared between different processes. Is this possible, and how?


Since the address of the base of the shared memory may (and usually
will) be different in each process, you can't use ordinary pointers to
refer to the next element of the list. Instead, you have to replace all
pointers with offsets from the base of the shared memory.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
Michael B Allen

2004-05-23, 1:31 am

On Sat, 22 May 2004 03:59:30 -0400, Xarky wrote:

> Hi,
> I would like to implement a linked list in memory that is to be
> shared between different processes. Is this possible, and how?


Sure. My personal tool-belt of stuff has examples of this:

http://www.ioplex.com/~miallen/libmba/

Specifically here's an example that does exactly what you ask:

http://www.ioplex.com/~miallen/libm...ts/SharedAdts.c

Note however my linkedlist doesn't currently use the ref_t business so it
can only be used if the mapping is inherited by all processes. Hashmap and
varray OTOH do use ref_t throughout so they can be mapped at runtime or
(de)serialized.

Regardless of what you choose to do, read the html api docs for the
suba(3m) module for my observations about sharing complex data structures
between processes. I recommend just following the technique I've used
though as it is portable, clean, tested, etc.

Mike
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com