[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: Static pools?

From: Garrett Rooney <rooneg_at_electricjellyfish.net>
Date: 2003-03-08 18:28:27 CET

On Saturday, March 8, 2003, at 12:09 PM, Matthew Hambley wrote:

> I want a block of memory which will last across calls to a function.
> i.e.
> a static, global to my source file. How do I go about achieving this
> with
> the memory pool system used by APR? Presumably I can't simply say:
>
> static FirstRun = (1 == 1);
> static BigOlStruc *TheStruc;
>
> void TheFunc(apr_pool_t *pool)
> {
> if (FirstRun) {
> TheStruc = apr_palloc(sizeof(BigOlStruc), pool);
> FirstRun = (1 == 0);
> }
> ...
>
> All sorts of crazy stuff might happen while I'm away, I could come
> back
> and find that my memory has been de-allocated.

let's ask a better question. why do you want to allocate a bunch of
static memory? static memory like that is generally a "bad thing"
(tm), especially from a thread safety point of view.

if you absolutely posetively without a doubt HAVE to do it, you could
create a new pool (with no parent) inside your first run block, and
allocate out of there... or you could hang it off the global pool like
we do for apr_xlate structures (but that's evil, and we want to stop
doing that).

-garrett

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sat Mar 8 18:29:12 2003

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.