2006-02-06 18:11:01 +00:00
|
|
|
/** \file halloc.h
|
|
|
|
|
2006-02-11 00:13:17 +00:00
|
|
|
A hierarchical memory allocation system. Works mostly like talloc
|
2006-02-06 18:11:01 +00:00
|
|
|
used in Samba, except that an arbitrary block allocated with
|
|
|
|
malloc() can be registered to be freed by halloc_free.
|
|
|
|
|
2006-02-06 14:25:02 +00:00
|
|
|
*/
|
|
|
|
|
2006-02-09 15:50:20 +00:00
|
|
|
#ifndef FISH_HALLOC_H
|
|
|
|
#define FISH_HALLOC_H
|
|
|
|
|
2006-02-06 14:25:02 +00:00
|
|
|
/**
|
2006-02-09 15:50:20 +00:00
|
|
|
Allocate new memory using specified parent memory context. Context
|
|
|
|
_must_ be either 0 or the result of a previous call to halloc.
|
2006-02-06 18:11:01 +00:00
|
|
|
|
2006-02-11 00:13:17 +00:00
|
|
|
If \c context is null, the resulting block is a root block, and
|
2006-02-09 15:50:20 +00:00
|
|
|
must be freed with a call to halloc_free().
|
2006-02-06 18:11:01 +00:00
|
|
|
|
2006-02-11 00:13:17 +00:00
|
|
|
If \c context is not null, context must be a halloc root block. the
|
|
|
|
resulting memory block is a child context, and must never be
|
|
|
|
explicitly freed, it will be automatically freed whenever the
|
2006-02-19 01:54:38 +00:00
|
|
|
parent context is freed. Child blocks can also never be used as the
|
2006-02-11 00:13:17 +00:00
|
|
|
context in calls to halloc_register_function, halloc_free, etc.
|
2006-02-06 14:25:02 +00:00
|
|
|
*/
|
|
|
|
void *halloc( void *context, size_t size );
|
|
|
|
|
2006-02-09 15:50:20 +00:00
|
|
|
/**
|
|
|
|
Make the specified function run whenever context is free'd, using data as argument.
|
2006-02-11 00:13:17 +00:00
|
|
|
|
|
|
|
\c context a halloc root block
|
2006-02-09 15:50:20 +00:00
|
|
|
*/
|
|
|
|
void halloc_register_function( void *context, void (*func)(void *), void *data );
|
|
|
|
|
2006-02-06 14:25:02 +00:00
|
|
|
/**
|
2006-02-06 18:11:01 +00:00
|
|
|
Free memory context and all children contexts. Only root contexts
|
|
|
|
may be freed explicitly.
|
2006-02-11 00:13:17 +00:00
|
|
|
|
|
|
|
All functions registered with halloc_register_function are run in
|
|
|
|
the order they where added. Afterwards, all memory allocated using
|
|
|
|
halloc itself is free'd.
|
|
|
|
|
|
|
|
\c context a halloc root block
|
2006-02-06 14:25:02 +00:00
|
|
|
*/
|
|
|
|
void halloc_free( void *context );
|
|
|
|
|
2006-02-09 15:50:20 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|