int main(int argc, char** argv) { size_t alloc_size = 2642080; size_t size = alloc_size + tlsf_size() + tlsf_pool_overhead() + tlsf_alloc_overhead(); void* memory = ::malloc(size); tlsf_t tlsf = tlsf_create_with_pool(memory,size); tlsf_walk_pool(tlsf_get_pool(tlsf),0,0); std::cout << "try alloc " << std::hex << alloc_size << std::endl; void* ptr = tlsf_malloc(tlsf,alloc_size); assert(ptr); ::free(memory); return 0; }
Allocator::Allocator(void) { impl = new AllocatorImpl; size_t default_size = 10*1024*1024; impl->pools = (next_t*)malloc(default_size); impl->pools->next = 0x0; impl->pools->pool_size = default_size; size_t off = tlsf_size() + tlsf_pool_overhead() + sizeof(next_t); //printf("Generated Memory Pool with '%p'\n", impl->pools); impl->tlsf = tlsf_create_with_pool(((char*)impl->pools)+off, default_size-2*off); //printf("Allocator(%p)\n", impl); }