Proposal: Pooled memory management

Fergus Henderson fjh at
Sat Jan 18 10:25:09 EST 2003

On 18-Jan-2003, Sven Panne <Sven.Panne at> wrote:
> The FFI libraries currently contain support for explicit allocation
> and deallocation via the malloc/free family and support for implicit
> allocation and deallocation via alloca and friends. But there is a
> very useful level between these extremes: Pooled memory management.
> Under this scheme, (re-)allocations belong to a given pool, and
> everything in a pool is deallocated when the pool itself is
> deallocated.
> You can find the implementation and the (lean) docs at:
> I propose adding this module to FFI addendum and the exports of module
> Foreign.Marshal. Although the module is definitely not a candidate for
> the next ACM award, it's a useful and common abstraction which can
> easily be implemented on the existing FFI modules.
> Comments?

In general, I think that support for pooled allocation is a very good idea.

With regard to the specific interface proposed here:
why is the Pool type polymorphic, and allocation in a pool restricted
to only allocating values whose type matches the pool's type parameter?
It would be much nicer to support allocating different types in the same pool.

The implementation at has
obviously not been adequately tested, since it contains at least one
bug: the lines

	pooledMallocArray0 pool size =
	   pooledMallocArray0 pool (size + 1)


should be

	pooledMallocArray0 pool size =
	   pooledMallocArray pool (size + 1)

Fergus Henderson <fjh at>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <>  |     -- the last words of T. S. Garp.

More information about the FFI mailing list