diff options
author | 2006-06-20 10:50:10 +1000 | |
---|---|---|
committer | 2006-06-20 10:50:10 +1000 | |
commit | 568803568043345e7971403f03769a485a73939c (patch) | |
tree | 56b3b435e6bd0448ccd90cf90b3e01470ab89ff6 /halloc.c | |
parent | 43b6b703ff56ed4a4194d26811823a6c4e545a87 (diff) |
Large number of sourcecode comment edits, and some minor code polish
darcs-hash:20060620005010-ac50b-eaeae9a6242a37c1e34831e1a0b2ee2b4e7a012e.gz
Diffstat (limited to 'halloc.c')
-rw-r--r-- | halloc.c | 57 |
1 files changed, 56 insertions, 1 deletions
@@ -18,37 +18,92 @@ #include "common.h" #include "halloc.h" +/** + Extra size to allocate whenever doing a halloc, in order to fill uyp smaller halloc calls +*/ #define HALLOC_BLOCK_SIZE 128 + +/** + Maximum size of trailing halloc space to refuse to discard +*/ #define HALLOC_SCRAP_SIZE 16 #ifdef HALLOC_DEBUG +/** + Debug statistic parameter +*/ static int child_count=0; +/** + Debug statistic parameter +*/ static int child_size=0; +/** + Debug statistic parameter +*/ static int alloc_count =0; +/** + Debug statistic parameter +*/ static int alloc_spill = 0; +/** + Debug statistic parameter +*/ static pid_t pid=0; +/** + Debug statistic parameter +*/ static int parent_count=0; #endif +/** + The main datastructure for a main halloc context +*/ typedef struct halloc { + /** + List of all addresses and functions to call on them + */ array_list_t children; + /** + Memory scratch area used to fullfil smaller memory allocations + */ void *scratch; + /** + Amount of free space in the scratch area + */ size_t scratch_free; - long long data[0]; +#if __STDC_VERSION__ < 199901L + /** + The actual data. MAde to be of type long long to make sure memory alignment is in order. + */ + long long data[1]; // Waste one byte on non-C99 compilers... :-( +#else + long long data[]; +#endif } halloc_t; +/** + Get the offset of the halloc structure before a data block +*/ static halloc_t *halloc_from_data( void *data ) { return (halloc_t *)(((char *)data) - sizeof( halloc_t ) ); } +/** + A function that does nothing +*/ static void late_free( void *data) { } #ifdef HALLOC_DEBUG +/** + Debug function, called at exit when in debug mode. Prints usage + statistics, like number of allocations and number of internal calls + to malloc. +*/ static void woot() { if( getpid() == pid ) |