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