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