httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sorin Manolache" <sor...@gmail.com>
Subject Re: Instance a c++ object on Apache shared memory
Date Thu, 10 Jul 2008 11:16:14 GMT
On Thu, Jul 10, 2008 at 12:17, lusob <luis.sobrecueva@gmail.com> wrote:
>
> Hello, and thanks for the example!
> My class has another class as data member (instead a struct). How can I
> allocate it in shared memory?

As far as I know you cannot. But maybe I'm wrong.

S

> Sorin Manolache wrote:
>>
>> On Thu, Jul 10, 2008 at 09:41, lusob <luis.sobrecueva@gmail.com> wrote:
>>>
>>> Hello,
>>> I'm developing an apache c++ module and I need to create a global
>>> persistent
>>> object for all the processes.
>>
>> Hi,
>>
>> I'm doing something similar.
>>
>> I declare
>>
>> static MyClass *my_object
>>
>> globally in your module c++ file.
>>
>>
>> Then I hook post_config. There, I do
>>
>> MyClass *my_object = new MyClass(config_pool);
>>
>>
>> In the constructor of MyClass I create a shared memory segment:
>>
>> class MyClass {
>> public:
>>    MyClass(apr_pool_t *config_pool) {
>>        apr_shm_create(&m, sizeof(MyStruct), 0, config_pool);
>>        shared = apr_shm_baseaddr_get(m);
>>        // when config_pool is destroyed, the shared memory segment and
>> this object are destroyed too
>>        apr_pool_cleanup_register(config_pool, this, (apr_status_t
>> (*)(void *))my_cleanup, NULL);
>>        init(shared);
>>    }
>>    ~MyClass() {
>>        tear_down(shared);
>>        apr_shm_destroy(m);
>>    }
>> private:
>>    apr_shm_t *m;
>>    MyStruct *shared;
>> };
>>
>> apr_status_t my_cleanup(MyClass *obj) {
>>    delete obj;
>> }
>>
>> --
>> S
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Instance-a-c%2B%2B-object-on-Apache-shared-memory-tp18377523p18379811.html
> Sent from the Apache HTTP Server - Module Writers mailing list archive at Nabble.com.
>
>

Mime
View raw message