Return-Path: Delivered-To: apmail-httpd-modules-dev-archive@locus.apache.org Received: (qmail 60868 invoked from network); 10 Jul 2008 10:17:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 10 Jul 2008 10:17:36 -0000 Received: (qmail 33341 invoked by uid 500); 10 Jul 2008 10:17:35 -0000 Delivered-To: apmail-httpd-modules-dev-archive@httpd.apache.org Received: (qmail 33321 invoked by uid 500); 10 Jul 2008 10:17:35 -0000 Mailing-List: contact modules-dev-help@httpd.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: modules-dev@httpd.apache.org Delivered-To: mailing list modules-dev@httpd.apache.org Received: (qmail 33310 invoked by uid 99); 10 Jul 2008 10:17:35 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Jul 2008 03:17:35 -0700 X-ASF-Spam-Status: No, hits=2.6 required=10.0 tests=DNS_FROM_OPENWHOIS,SPF_HELO_PASS,SPF_PASS,WHOIS_MYPRIVREG X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of lists@nabble.com designates 216.139.236.158 as permitted sender) Received: from [216.139.236.158] (HELO kuber.nabble.com) (216.139.236.158) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Jul 2008 10:16:42 +0000 Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1KGtCy-00017E-6I for modules-dev@httpd.apache.org; Thu, 10 Jul 2008 03:17:04 -0700 Message-ID: <18379811.post@talk.nabble.com> Date: Thu, 10 Jul 2008 03:17:04 -0700 (PDT) From: lusob To: modules-dev@httpd.apache.org Subject: Re: Instance a c++ object on Apache shared memory In-Reply-To: <20170a030807100201u3ee38ecdk1d1e8e78ef0f1e09@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: luis.sobrecueva@gmail.com References: <18377523.post@talk.nabble.com> <20170a030807100201u3ee38ecdk1d1e8e78ef0f1e09@mail.gmail.com> X-Virus-Checked: Checked by ClamAV on apache.org 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 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.