You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Al...@csiro.au on 2006/03/22 07:58:20 UTC

utilizing APR in existing c++ app

Hi,

I was wondering if there was any documentation in terms of strategies
for utilizing APR in an existing c++ codebase? The main problem I have
is how to deal with the memory pools that are required for APR
functions. Is it best to create one giant global pool for the entire
application and have all APR functions use the global pool, or is it
better to have a pool exist per object for the lifetime of an object and
all APR usage within that object utilise its own pool? Any suggestions?

Re: utilizing APR in existing c++ app

Posted by Nick Kew <ni...@webthing.com>.
On Wednesday 22 March 2006 06:58, Alex.Krumm-Heller@csiro.au wrote:
> Hi,
>
> I was wondering if there was any documentation in terms of strategies
> for utilizing APR in an existing c++ codebase? 

There are a couple of suggestions in my article at
http://www.apachetutor.org/dev/pools
But since you already know enough to pose the question,
they'll probably already have occurred to you.

Apart from that - what Garrett and Michael said :-)

-- 
Nick Kew

Re: utilizing APR in existing c++ app

Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On 3/21/06, Alex.Krumm-Heller@csiro.au <Al...@csiro.au> wrote:
> Hi,
>
> I was wondering if there was any documentation in terms of strategies
> for utilizing APR in an existing c++ codebase? The main problem I have
> is how to deal with the memory pools that are required for APR
> functions. Is it best to create one giant global pool for the entire
> application and have all APR functions use the global pool, or is it
> better to have a pool exist per object for the lifetime of an object and
> all APR usage within that object utilise its own pool? Any suggestions?

Creating one global pool is fine, but you can't just allocate
everything out of it, you need to use subpool that are scoped
appropriately for whatever you're using them for.  The idea is to
allocate out of a pool that lasts long enough for whatever you're
using, and then to clear that pool when you're done with it.  If you
just allocate out of a large pool you get a giant memory leak.

Making an object carry around a pool isn't especially good either,
since then you have no control over how much gets allocated in its
pool, it's all depending on how many times methods that make use of
the pool get called.

The right way to do it really means passing memory pools around in
code that uses APR, since that code is the only place you have enough
knowledge of object lifetimes to do reasonable pool management.

See http://subversion.tigris.org/hacking.html#apr-pools for a
description of how the Subversion project has decided to use pools,
those guidelines came about after we made most of the mistakes you're
talking about doing, and had to fix things the hard way afterwards.

-garrett

Re: utilizing APR in existing c++ app

Posted by Antonio Alvarado Hernández <aa...@gmail.com>.
On 3/24/06, Garrett Rooney <ro...@electricjellyfish.net> wrote:
> On 3/23/06, Antonio Alvarado Hernández <aa...@gmail.com> wrote:
> > Hello -I'm new in this mailist- first at all, congratulations to all
> > APR project comunity members for your very good job!
> >
> > So, maybe possible -in a near/far future- to include C++ wrapper like
> > this one in the main APR distribution? or, this stuff must to be in an
> > APR++ separated project?
>
> I suspect you probably wanted to send this to the list, not me personally.

Absolutely,  I'm so sorry :-(

>
> The answer though is that I imagine we'd consider it if there were
> enough people willing to actually work on it.  I just tossed that
> together on a whim because I wanted to see how it would work.  It's
> not really all that useful without an application looking to use it to
> drive the development though.  Awful theoretical until you're actually
> at that point.
>

Yes I mean, my interest could be in that direction because I'm
planning to use APR (wrapped of course) as a base for a lightweight 
C++ networking framework ala Twisted Project.  This is the root of my
question ;-)

Antonio

Re: utilizing APR in existing c++ app

Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On 3/23/06, James Mansion <ja...@wgold.demon.co.uk> wrote:
> I've seen a snazzy template for doing that - but I can't remember where.
>
> Maybe Google will find it.

Perhaps you were thinking of:

http://people.apache.org/~rooneg/apr.hxx

-garrett

RE: utilizing APR in existing c++ app

Posted by James Mansion <ja...@wgold.demon.co.uk>.
I've seen a snazzy template for doing that - but I can't remember where.

Maybe Google will find it.

James

-----Original Message-----
From: Michael Vergoz [mailto:mv@binarysec.com]
Sent: 22 March 2006 09:49
To: Alex.Krumm-Heller@csiro.au; dev@apr.apache.org
Subject: Re: utilizing APR in existing c++ app


Hi,

There is no really difference between using APR with C or C++ excepting
callbacks.
In general you don't need to create a pool per object. You should to use the
existing pool (depends your application).
Here is an example :
static apr_status_t my_callback_destructor(void *data) {
            obj *myobj = (obj *)data;
            delete myobj;
}

int afunction(apr_pool_t *pool) {
            obj *myobj = new obj;
            apr_pool_cleanup_register(pool, (void *)myobj,
my_callback_destructor, my_callback_destructor);
}

Michael Vergoz

From: <Al...@csiro.au>
To: <de...@apr.apache.org>
Sent: Wednesday, March 22, 2006 7:58 AM
Subject: utilizing APR in existing c++ app


Hi,

I was wondering if there was any documentation in terms of strategies
for utilizing APR in an existing c++ codebase? The main problem I have
is how to deal with the memory pools that are required for APR
functions. Is it best to create one giant global pool for the entire
application and have all APR functions use the global pool, or is it
better to have a pool exist per object for the lifetime of an object and
all APR usage within that object utilise its own pool? Any suggestions?




Re: utilizing APR in existing c++ app

Posted by Michael Vergoz <mv...@binarysec.com>.
Hi,

There is no really difference between using APR with C or C++ excepting 
callbacks.
In general you don't need to create a pool per object. You should to use the 
existing pool (depends your application).
Here is an example :
static apr_status_t my_callback_destructor(void *data) {
            obj *myobj = (obj *)data;
            delete myobj;
}

int afunction(apr_pool_t *pool) {
            obj *myobj = new obj;
            apr_pool_cleanup_register(pool, (void *)myobj, 
my_callback_destructor, my_callback_destructor);
}

Michael Vergoz

From: <Al...@csiro.au>
To: <de...@apr.apache.org>
Sent: Wednesday, March 22, 2006 7:58 AM
Subject: utilizing APR in existing c++ app


Hi,

I was wondering if there was any documentation in terms of strategies
for utilizing APR in an existing c++ codebase? The main problem I have
is how to deal with the memory pools that are required for APR
functions. Is it best to create one giant global pool for the entire
application and have all APR functions use the global pool, or is it
better to have a pool exist per object for the lifetime of an object and
all APR usage within that object utilise its own pool? Any suggestions?