heap.h

00001 /*
00002  * heap.h
00003  */
00108 #ifndef _lub_heap_h
00109 #define _lub_heap_h
00110 #include <stddef.h>
00111 
00112 #include "lub/types.h"
00113 
00117 typedef struct lub_heap_s lub_heap_t;
00118 
00122 typedef struct lub_heap_free_block_s lub_heap_free_block_t;
00123 
00127 typedef struct lub_heap_stats_s lub_heap_stats_t;
00128 struct lub_heap_stats_s
00129 {
00130     /*----------------------------------------------------- */
00134     unsigned int segs;
00138     size_t segs_bytes;
00142     unsigned int segs_overhead;
00143     /*----------------------------------------------------- */
00148     unsigned int free_blocks;
00152     size_t free_bytes;
00156     unsigned int free_overhead;
00157     /*----------------------------------------------------- */
00162     unsigned int alloc_blocks;
00167     size_t alloc_bytes;
00171     unsigned int alloc_overhead;
00172     /*----------------------------------------------------- */
00177     unsigned int alloc_total_blocks;
00182     size_t alloc_total_bytes;
00183     /*----------------------------------------------------- */
00188     unsigned int alloc_hightide_blocks;
00194     size_t alloc_hightide_bytes;
00199     size_t alloc_hightide_overhead;
00204     unsigned int free_hightide_blocks;
00208     size_t free_hightide_bytes;
00212     size_t free_hightide_largest;
00217     size_t free_hightide_overhead;
00218     /*----------------------------------------------------- */
00223     unsigned int static_blocks;
00228     size_t static_bytes;    
00233     size_t static_overhead;
00234     /*----------------------------------------------------- */
00235 };
00240 typedef enum
00241 {
00245     LUB_HEAP_OK,
00249     LUB_HEAP_FAILED,
00254     LUB_HEAP_DOUBLE_FREE,
00259     LUB_HEAP_CORRUPTED,
00264     LUB_HEAP_INVALID_POINTER
00265 } lub_heap_status_t;
00266 
00271 typedef enum
00272 {
00277     LUB_HEAP_ALIGN_NATIVE = sizeof(struct {void *ptr;}),
00281     LUB_HEAP_ALIGN_4    = 0x00000004,
00285     LUB_HEAP_ALIGN_8    = 0x00000008,
00289     LUB_HEAP_ALIGN_16   = 0x00000010,
00293     LUB_HEAP_ALIGN_32   = 0x00000020,
00297     LUB_HEAP_ALIGN_64   = 0x00000040,
00301     LUB_HEAP_ALIGN_128  = 0x00000080,
00305     LUB_HEAP_ALIGN_256  = 0x00000100,
00309     LUB_HEAP_ALIGN_512  = 0x00000200,
00313     LUB_HEAP_ALIGN_1024  = 0x00000400,
00317     LUB_HEAP_ALIGN_2048  = 0x00000800,
00321     LUB_HEAP_ALIGN_4096  = 0x00001000,
00325     LUB_HEAP_ALIGN_8192  = 0x00002000,
00329     LUB_HEAP_ALIGN_16384 = 0x00004000,
00333     LUB_HEAP_ALIGN_32768 = 0x00008000
00334 } lub_heap_align_t;
00335 
00339 typedef enum
00340 {
00345     LUB_HEAP_SHOW_LEAKS,
00350     LUB_HEAP_SHOW_PARTIALS,
00354     LUB_HEAP_SHOW_ALL
00355 } lub_heap_show_e;
00356 
00361 typedef void 
00362     lub_heap_foreach_fn(
00366         void *block,
00370         unsigned index,
00374         size_t size,
00378         void *arg);
00379 
00396 void
00397     lub_heap_foreach_segment(
00401         lub_heap_t *instance,
00405         lub_heap_foreach_fn *fn,
00410         void *arg);
00427 void
00428     lub_heap_foreach_free_block(
00432         lub_heap_t *instance,
00436         lub_heap_foreach_fn *fn,
00441         void *arg);
00442 
00459 lub_heap_t *
00460     lub_heap_create(
00465         void *start,
00469         size_t size
00470     );
00484 void 
00485     lub_heap_add_segment(
00489         lub_heap_t *instance,
00493         void *start,
00497         size_t size
00498     );
00518 void *
00519     lub_heap_static_alloc(
00523         lub_heap_t *instance,
00527         size_t size
00528     );
00553 lub_heap_status_t
00554     lub_heap_realloc(
00558         lub_heap_t *instance,
00563         char **ptr,
00567         size_t size,
00571         lub_heap_align_t alignment
00572     );
00597 bool_t
00598     lub_heap_taint(
00602         bool_t enable
00603     );
00618 bool_t
00619     lub_heap_is_tainting(void);
00643 bool_t
00644     lub_heap_check(
00648         bool_t enable
00649     );
00650 
00665 bool_t
00666     lub_heap_is_checking(void);
00667 
00683 extern bool_t 
00684     lub_heap_check_memory(lub_heap_t *this);
00685 
00691 void 
00692     lub_heap_stop_here(
00696         lub_heap_status_t status,
00700         char *old_ptr,
00704         size_t new_size
00705     );
00706 
00718 void
00719     lub_heap__get_stats(
00723         lub_heap_t *instance,
00727         lub_heap_stats_t *stats
00728     );
00729 
00733 void
00734     lub_heap_show(
00738         lub_heap_t *instance,
00742         bool_t verbose
00743     );
00756 size_t    
00757 lub_heap__get_max_free(
00761         lub_heap_t *instance
00762     );
00763 
00764 extern size_t
00765     lub_heap__get_block_overhead(void);
00766 
00767 extern size_t
00768     lub_heap__get_block_size(const void *ptr);
00777 void
00778     lub_heap_show_leaks(
00782         lub_heap_show_e how
00783     );
00784 
00785 void
00786     lub_heap__set_framecount(
00790         unsigned framecount
00791     );
00792 
00793 unsigned
00794     lub_heap__get_framecount(void);
00795     
00796 extern bool_t 
00797     lub_heap_validate_pointer(lub_heap_t *this,
00798                               char       *ptr);
00805 #define LUB_HEAP_ZERO_ALLOC ((void*)-1)
00806 
00807 #endif /* _lub_heap_h */
00808 

Generated on Fri Jun 2 10:49:38 2006 for CLISH by  doxygen 1.4.6