apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sander Striker" <stri...@apache.org>
Subject RE: Memory management question
Date Mon, 28 Oct 2002 14:03:23 GMT
> From: Damir Dezeljin [mailto:programing@nib.si]
> Sent: 28 October 2002 14:06

> Hi again.
> Remote address patch seams to work fine. 10x to all.
> I now have some other questions. I'm envolved in constructing an data
> structure (something similar to queue). I will use it during my program.
> The lifetime of such a data structure (queue) should grow up to various
> hours. I allocate a new node for each data form the memory pool alocated
> for the queue. When I don't need a data any more, I just unlink it (lose
> the reference to the allocated memory). What will happen with the memory?

The memory will 'leak' away until you clear or destroy the pool.
> Ex.:
> What will happen if I allocate in a loop 100.000.000 pointers to int *
> from a pool and then simply lose the reference to this pointer. Will this
> ocupy 400.000.000 bytes of memory or will some sort of garbage collector
> free those data?

It will occupy the 400MB of mem.

> If no ... how can I free those data when I don't need them any more. Do I
> have to alocate a new pool for eacy leaf and then destroy it?

That wouldn't be the approach I would pursue ;)

> Is it a big waste of time?

Nah.  What you want is a custom allocator.  Look at the bucket allocator
in apr-util for an example on how to do this.


View raw message