httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r.@tuxteam.de
Subject Re: Binary Tree Shared Memory Problem
Date Tue, 29 Nov 2011 09:59:28 GMT
On Tue, Nov 29, 2011 at 12:29:20AM +0200, O??uzhan TOPG?L wrote:
> Hi, is there any example mod_slotmem codes that we can understand the
> usage? 

Have you looked at the code? 'mod_slotmem_shm.c' is less than 650 lines
of code, 'mod_slotmem_plain.c' less than 300. Sorry, but you have to do
_some_ reading yourself. 

> Or could you give me an usage example? For example we are using
> apr_shm_create() in post_config, but mod_slotmem is a little bit hard to
> understand i think.
> And i want to ask a question,
> is it a problem to create
> 
> typedef struct node {
>     ELEMENT node_element;
>     struct node *left;
>     struct node *right;
> }NODE;
> 
> kind of struct. A struct that has two struct elements. 

No, it doesn't. It holds two _pointers_ to node structures (learn some C
as well ..). You can't share such a structure since the address in *left or *right 
will only be valid in one process.
You could store an offset to the node's base address in left/right and
write some support code to do all the pointer magic to get/set these
values but you still would need to write your own memory allocator and
tree balancing code and somehow I get the feeling that's to demanding a
task ...
We've had similr questions in the ML just recently - consult the
archive.


 HTH Ralf Mattes
 
> As i mentioned
> before what i'm trying to implement is a binary tree as a data structure.
> 
> regards
> 
> O??uzhan TOPGÜL
> 
> 
> On Mon, Nov 28, 2011 at 11:52 PM, Ignaz Birnstingl <ignazb@gmail.com> wrote:
> 
> > Hi,
> >
> > apr_shm_baseaddr_get returns the base address for the shared memory
> > segment. You will have to implement your own "allocator" within the shared
> > memory. Also keep in mind that you can't reliably use pointers inside the
> > shared memory segment, because - as the documentation states - the address
> > returned by apr_shm_baseaddr_get "is only usable within the callers address
> > space, since this API does not guarantee that other attaching processes
> > will maintain the same address mapping."
> > Inter- and intra-process synchronization will be problems you will
> > encounter later on.
> > Btw Apache 2.3 offers mod_slotmem which helps in using shared memory -
> > maybe you should have a look at it?
> >
> > -- Ignaz
> >

Mime
View raw message