/src/memory/tlsf/tlsf.h
C++ Header | 69 lines | 23 code | 13 blank | 33 comment | 0 complexity | 0215ea5ec3dfb216ccc320847fc04a5c MD5 | raw file
1#ifndef INCLUDED_tlsf 2#define INCLUDED_tlsf 3 4/// @addtogroup MemorySubsystem 5/// @{ 6 7/* 8** Two Level Segregated Fit memory allocator, version 1.9. 9** Written by Matthew Conte, and placed in the Public Domain. 10** http://tlsf.baisoku.org 11** 12** Based on the original documentation by Miguel Masmano: 13** http://rtportal.upv.es/rtmalloc/allocators/tlsf/index.shtml 14** 15** Please see the accompanying Readme.txt for implementation 16** notes and caveats. 17** 18** This implementation was written to the specification 19** of the document, therefore no GPL restrictions apply. 20*/ 21 22#include <stddef.h> 23 24#if defined(__cplusplus) 25extern "C" { 26#endif 27 28/* Create/destroy a memory pool. */ 29/// Type of TLSF pool 30typedef void* tlsf_pool; 31/// Create TLSF pool on chunk of memory 32tlsf_pool tlsf_create(void* mem, size_t bytes); 33/// Destroy TLSF pool 34/// @note You should destroy underlying block yourself. 35void tlsf_destroy(tlsf_pool pool); 36 37/* malloc/memalign/realloc/free replacements. */ 38/// Allocate block 39void* tlsf_malloc(tlsf_pool pool, size_t bytes); 40/// Allocate aligned block 41void* tlsf_memalign(tlsf_pool pool, size_t align, size_t bytes); 42/// Realloc block 43void* tlsf_realloc(tlsf_pool pool, void* ptr, size_t size); 44/// Free block 45void tlsf_free(tlsf_pool pool, void* ptr); 46 47/* Debugging. */ 48typedef void (*tlsf_walker)(void* ptr, size_t size, int used, void* user); 49/// Heap walker 50void tlsf_walk_heap(tlsf_pool pool, tlsf_walker walker, void* user); 51/// Returns nonzero if heap check fails. 52int tlsf_check_heap(tlsf_pool pool); 53 54/// Returns internal block size, not original request size 55size_t tlsf_block_size(void* ptr); 56 57/// Overhead of per-pool internal structures. 58size_t tlsf_overhead(); 59 60/// Get total size and free size 61void tlsf_statistics(tlsf_pool tlsf, size_t* total_size, size_t* free_size); 62 63#if defined(__cplusplus) 64}; 65#endif 66 67/// @? 68 69#endif