12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- #include "private.h"
- #include "context.h"
- static int lub_heap_block_compare(const void *clientnode, const void *clientkey)
- {
- int delta;
- const lub_heap_free_block_t *block = clientnode;
- const lub_heap_key_t *key = clientkey;
- delta = (block->tag.words - key->words);
- if (0 == delta) {
-
- delta = (block - key->block);
- }
- return delta;
- }
- lub_heap_t *lub_heap_create(void *start, size_t size)
- {
- lub_heap_t *this = NULL;
-
- if (size > (sizeof(lub_heap_t) + 4)) {
- this = start;
-
- lub_bintree_init(&this->free_tree,
- offsetof(lub_heap_free_block_t, bt_node),
- lub_heap_block_compare, lub_heap_block_getkey);
- this->cache = 0;
- this->suppress = 0;
-
- this->stats.segs = 0;
- this->stats.segs_bytes = 0;
- this->stats.segs_overhead = 0;
- this->stats.free_blocks = 0;
- this->stats.free_bytes = 0;
- this->stats.free_overhead = 0;
- this->stats.static_blocks = 0;
- this->stats.static_bytes = 0;
- this->stats.static_overhead = 0;
- this->stats.alloc_blocks = 0;
- this->stats.alloc_bytes = 0;
- this->stats.alloc_overhead = 0;
- this->stats.alloc_hightide_blocks = 0;
- this->stats.alloc_hightide_bytes = 0;
- this->stats.alloc_hightide_overhead = 0;
- this->stats.free_hightide_blocks = 0;
- this->stats.free_hightide_bytes = 0;
- this->stats.free_hightide_overhead = 0;
- this->stats.alloc_total_blocks = 0;
- this->stats.alloc_total_bytes = 0;
-
- this->first_segment.next = NULL;
-
- lub_heap_add_segment(this,
- &this->first_segment,
- size - sizeof(lub_heap_t) +
- sizeof(lub_heap_segment_t));
- this->stats.segs_overhead += sizeof(lub_heap_t);
-
- {
- lub_heap_leak_t *leak = lub_heap_leak_instance();
- this->next = leak->m_heap_list;
- leak->m_heap_list = this;
- lub_heap_leak_release(leak);
- }
- }
- return this;
- }
|