[164] | 1 | #ifndef INCLUDED_tlsf
|
---|
| 2 | #define INCLUDED_tlsf
|
---|
| 3 |
|
---|
| 4 | /*
|
---|
| 5 | ** Two Level Segregated Fit memory allocator, version 3.0.
|
---|
| 6 | ** Written by Matthew Conte, and placed in the Public Domain.
|
---|
| 7 | ** http://tlsf.baisoku.org
|
---|
| 8 | **
|
---|
| 9 | ** Based on the original documentation by Miguel Masmano:
|
---|
| 10 | ** http://rtportal.upv.es/rtmalloc/allocators/tlsf/index.shtml
|
---|
| 11 | **
|
---|
| 12 | ** Please see the accompanying Readme.txt for implementation
|
---|
| 13 | ** notes and caveats.
|
---|
| 14 | **
|
---|
| 15 | ** This implementation was written to the specification
|
---|
| 16 | ** of the document, therefore no GPL restrictions apply.
|
---|
| 17 | */
|
---|
| 18 |
|
---|
| 19 | #include <t_stddef.h>
|
---|
| 20 |
|
---|
| 21 | #if defined(__cplusplus)
|
---|
| 22 | extern "C" {
|
---|
| 23 | #endif
|
---|
| 24 |
|
---|
| 25 | /* tlsf_t: a TLSF structure. Can contain 1 to N pools. */
|
---|
| 26 | /* pool_t: a block of memory that TLSF can manage. */
|
---|
| 27 | typedef void* tlsf_t;
|
---|
| 28 | typedef void* pool_t;
|
---|
| 29 |
|
---|
| 30 | /* Create/destroy a memory pool. */
|
---|
| 31 | tlsf_t tlsf_create(void* mem);
|
---|
| 32 | tlsf_t tlsf_create_with_pool(void* mem, size_t bytes);
|
---|
| 33 | void tlsf_destroy(tlsf_t tlsf);
|
---|
| 34 | pool_t tlsf_get_pool(tlsf_t tlsf);
|
---|
| 35 |
|
---|
| 36 | /* Add/remove memory pools. */
|
---|
| 37 | pool_t tlsf_add_pool(tlsf_t tlsf, void* mem, size_t bytes);
|
---|
| 38 | void tlsf_remove_pool(tlsf_t tlsf, pool_t pool);
|
---|
| 39 |
|
---|
| 40 | /* malloc/memalign/realloc/free replacements. */
|
---|
| 41 | void* tlsf_malloc(tlsf_t tlsf, size_t bytes);
|
---|
| 42 | void* tlsf_memalign(tlsf_t tlsf, size_t align, size_t bytes);
|
---|
| 43 | void* tlsf_realloc(tlsf_t tlsf, void* ptr, size_t size);
|
---|
| 44 | void tlsf_free(tlsf_t tlsf, void* ptr);
|
---|
| 45 |
|
---|
| 46 | /* Returns internal block size, not original request size */
|
---|
| 47 | size_t tlsf_block_size(void* ptr);
|
---|
| 48 |
|
---|
| 49 | /* Overheads/limits of internal structures. */
|
---|
| 50 | size_t tlsf_size();
|
---|
| 51 | size_t tlsf_align_size();
|
---|
| 52 | size_t tlsf_block_size_min();
|
---|
| 53 | size_t tlsf_block_size_max();
|
---|
| 54 | size_t tlsf_pool_overhead();
|
---|
| 55 | size_t tlsf_alloc_overhead();
|
---|
| 56 |
|
---|
| 57 | /* Debugging. */
|
---|
| 58 | typedef void (*tlsf_walker)(void* ptr, size_t size, int used, void* user);
|
---|
| 59 | void tlsf_walk_pool(pool_t pool, tlsf_walker walker, void* user);
|
---|
| 60 | /* Returns nonzero if any internal consistency check fails. */
|
---|
| 61 | int tlsf_check(tlsf_t tlsf);
|
---|
| 62 | int tlsf_check_pool(pool_t pool);
|
---|
| 63 |
|
---|
| 64 | #if defined(__cplusplus)
|
---|
| 65 | };
|
---|
| 66 | #endif
|
---|
| 67 |
|
---|
| 68 | #endif
|
---|