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?
Thanks again!!
Sorin Manolache wrote:
>
> On Thu, Jul 10, 2008 at 09:41, lusob <[EMAIL PROTECTED]> 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.