You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Rajalakshmi Iyer <ra...@blismobile.com> on 2012/03/21 12:31:30 UTC

Using apr_hash_t within shared memory

Hello,

I want to be able to store a hash map (apr_hash_t) in the Apache shared
memory (created using apr_shm_create). This map will be created once and
will be shared by all child processes.

However, when I try to access the hash stored in the shared memory, I get a
segmentation fault (because the hash appears empty).

I have ensured that I use the apr_shm_baseaddr_get to get the starting
address for the map in shared memory correctly.

However that does not seem to help.

Note that I have tried the same code with simple data structures like char*
etc and it works. Do I need to do something more to get a hash into and out
of the shared memory?

Thanks in advance!

-- 
Twitter: @Blismobile <http://twitter.com/#!/blismobile>
BlisMobile Media 
32 Percy Street,
London W1T 2DE
www.blismobile.com
[image: BlisMobile] <http://www.blismobile.com/>[image: Follow on Twitter]<http://twitter.com/#!/blismobile>[image: 
Blis Website] <http://www.blismobile.com/>

This communication is from BlisMobile Media, which is a trading name of 
Breeze Tech (UK) Ltd, a company registered in England and Wales with 
registered number 06455773. Its registered office is 32 Percy Street, 
London W1T 2DE, United Kingdom.

 

This communication contains information that is confidential and may also 
be privileged. It is for the exclusive use of the intended recipient(s). If 
you are not the intended recipient(s), please (1) notify info@blismobile.com by 
forwarding this email and delete all copies from your system and (2) note 
that disclosure, distribution, copying or use of this communication is 
strictly prohibited. Email communications cannot be guaranteed to be secure 
or free from error or viruses. All emails sent to or from a Blismobile 
email account are securely archived and stored by an external supplier. This 
email does not constitute a contractual agreement; such agreements are in 
specified contractual or Insertion Order (IO) form only 
and exclusively contain all the terms to which Breeze Tech )UK) Ltd will be 
bound. To the extent permitted by law, Breeze Tech (UK) Ltd does not accept 
any liability for use of or reliance on the contents of this email by any 
person save by the intended recipient(s) to the extent agreed in a contract 
or Insertion Order.

 

Opinions, conclusions and other information in this email which have not 
been delivered by way of the business of Breeze Tech (UK) Ltd are neither 
given nor endorsed by it.

Re: Using apr_hash_t within shared memory

Posted by Nick Kew <ni...@apache.org>.
On Wed, 21 Mar 2012 11:31:30 +0000
Rajalakshmi Iyer <ra...@blismobile.com> wrote:

> Hello,
> 
> I want to be able to store a hash map (apr_hash_t) in the Apache shared
> memory (created using apr_shm_create). This map will be created once and
> will be shared by all child processes.

You can't.  Well, not unless you hack deep in APR to allocate from shm.

But you can achieve a shared hash using mod_socache.

-- 
Nick Kew

Re: Using apr_hash_t within shared memory

Posted by Sorin Manolache <so...@gmail.com>.
On 2012-03-21 12:31, Rajalakshmi Iyer wrote:
> Hello,
>
> I want to be able to store a hash map (apr_hash_t) in the Apache shared
> memory (created using apr_shm_create). This map will be created once and
> will be shared by all child processes.
>
> However, when I try to access the hash stored in the shared memory, I get a
> segmentation fault (because the hash appears empty).
>
> I have ensured that I use the apr_shm_baseaddr_get to get the starting
> address for the map in shared memory correctly.
>
> However that does not seem to help.
>
> Note that I have tried the same code with simple data structures like char*
> etc and it works. Do I need to do something more to get a hash into and out
> of the shared memory?
>
> Thanks in advance!

I don't think you can put it into shared memory. It uses an apr_pool in 
order to allocate new data when you add elements to the hash. The 
apr_pool will allocate non-shared memory.

If your code is C++ or can be migrated to C++, have a look here: 
http://www.boost.org/doc/libs/1_49_0/doc/html/interprocess/allocators_containers.html#interprocess.allocators_containers.containers_explained

Sorin