2010-09-18 09:51:16 +08:00
|
|
|
/** \file halloc.h
|
2006-02-07 02:11:01 +08:00
|
|
|
|
2006-02-11 08:13:17 +08:00
|
|
|
A hierarchical memory allocation system. Works mostly like talloc
|
2006-02-07 02:11:01 +08:00
|
|
|
used in Samba, except that an arbitrary block allocated with
|
|
|
|
malloc() can be registered to be freed by halloc_free.
|
|
|
|
|
2006-02-06 22:25:02 +08:00
|
|
|
*/
|
|
|
|
|
2006-02-09 23:50:20 +08:00
|
|
|
#ifndef FISH_HALLOC_H
|
|
|
|
#define FISH_HALLOC_H
|
|
|
|
|
2006-02-06 22:25:02 +08:00
|
|
|
/**
|
2006-02-09 23:50:20 +08:00
|
|
|
Allocate new memory using specified parent memory context. Context
|
2006-10-26 18:22:53 +08:00
|
|
|
_must_ be either 0 or the result of a previous call to halloc. The
|
|
|
|
resulting memory is set to zero.
|
2006-02-07 02:11:01 +08:00
|
|
|
|
2006-02-11 08:13:17 +08:00
|
|
|
If \c context is null, the resulting block is a root block, and
|
2006-02-09 23:50:20 +08:00
|
|
|
must be freed with a call to halloc_free().
|
2006-02-07 02:11:01 +08:00
|
|
|
|
2006-02-11 08:13:17 +08: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 09:54:38 +08:00
|
|
|
parent context is freed. Child blocks can also never be used as the
|
2006-02-11 08:13:17 +08:00
|
|
|
context in calls to halloc_register_function, halloc_free, etc.
|
2006-02-06 22:25:02 +08:00
|
|
|
*/
|
|
|
|
void *halloc( void *context, size_t size );
|
|
|
|
|
2006-02-09 23:50:20 +08:00
|
|
|
/**
|
|
|
|
Make the specified function run whenever context is free'd, using data as argument.
|
2006-02-11 08:13:17 +08:00
|
|
|
|
|
|
|
\c context a halloc root block
|
2006-02-09 23:50:20 +08:00
|
|
|
*/
|
|
|
|
void halloc_register_function( void *context, void (*func)(void *), void *data );
|
|
|
|
|
2006-02-06 22:25:02 +08:00
|
|
|
/**
|
2006-02-07 02:11:01 +08:00
|
|
|
Free memory context and all children contexts. Only root contexts
|
|
|
|
may be freed explicitly.
|
2006-02-11 08:13:17 +08: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 22:25:02 +08:00
|
|
|
*/
|
|
|
|
void halloc_free( void *context );
|
|
|
|
|
2006-02-09 23:50:20 +08:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|