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