1 | #ifndef INCLUDED_tlsf
|
---|
2 | #define INCLUDED_tlsf
|
---|
3 |
|
---|
4 | /*
|
---|
5 | ** Two Level Segregated Fit memory allocator, version 3.1.
|
---|
6 | ** Written by Matthew Conte
|
---|
7 | ** http://tlsf.baisoku.org
|
---|
8 | **
|
---|
9 | ** Based on the original documentation by Miguel Masmano:
|
---|
10 | ** http://www.gii.upv.es/tlsf/main/docs
|
---|
11 | **
|
---|
12 | ** This implementation was written to the specification
|
---|
13 | ** of the document, therefore no GPL restrictions apply.
|
---|
14 | **
|
---|
15 | ** Copyright (c) 2006-2016, Matthew Conte
|
---|
16 | ** All rights reserved.
|
---|
17 | **
|
---|
18 | ** Redistribution and use in source and binary forms, with or without
|
---|
19 | ** modification, are permitted provided that the following conditions are met:
|
---|
20 | ** * Redistributions of source code must retain the above copyright
|
---|
21 | ** notice, this list of conditions and the following disclaimer.
|
---|
22 | ** * Redistributions in binary form must reproduce the above copyright
|
---|
23 | ** notice, this list of conditions and the following disclaimer in the
|
---|
24 | ** documentation and/or other materials provided with the distribution.
|
---|
25 | ** * Neither the name of the copyright holder nor the
|
---|
26 | ** names of its contributors may be used to endorse or promote products
|
---|
27 | ** derived from this software without specific prior written permission.
|
---|
28 | **
|
---|
29 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
---|
30 | ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
---|
31 | ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
32 | ** DISCLAIMED. IN NO EVENT SHALL MATTHEW CONTE BE LIABLE FOR ANY
|
---|
33 | ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
---|
34 | ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
---|
35 | ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
---|
36 | ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
37 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
---|
38 | ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
39 | */
|
---|
40 |
|
---|
41 | #include <stddef.h>
|
---|
42 |
|
---|
43 | #if defined(__cplusplus)
|
---|
44 | extern "C" {
|
---|
45 | #endif
|
---|
46 |
|
---|
47 | /* tlsf_t: a TLSF structure. Can contain 1 to N pools. */
|
---|
48 | /* pool_t: a block of memory that TLSF can manage. */
|
---|
49 | typedef void* tlsf_t;
|
---|
50 | typedef void* pool_t;
|
---|
51 |
|
---|
52 | /* Create/destroy a memory pool. */
|
---|
53 | tlsf_t tlsf_create(void* mem);
|
---|
54 | tlsf_t tlsf_create_with_pool(void* mem, size_t bytes);
|
---|
55 | void tlsf_destroy(tlsf_t tlsf);
|
---|
56 | pool_t tlsf_get_pool(tlsf_t tlsf);
|
---|
57 |
|
---|
58 | /* Add/remove memory pools. */
|
---|
59 | pool_t tlsf_add_pool(tlsf_t tlsf, void* mem, size_t bytes);
|
---|
60 | void tlsf_remove_pool(tlsf_t tlsf, pool_t pool);
|
---|
61 |
|
---|
62 | /* malloc/memalign/realloc/free replacements. */
|
---|
63 | void* tlsf_malloc(tlsf_t tlsf, size_t bytes);
|
---|
64 | void* tlsf_memalign(tlsf_t tlsf, size_t align, size_t bytes);
|
---|
65 | void* tlsf_realloc(tlsf_t tlsf, void* ptr, size_t size);
|
---|
66 | void tlsf_free(tlsf_t tlsf, void* ptr);
|
---|
67 |
|
---|
68 | /* Returns internal block size, not original request size */
|
---|
69 | size_t tlsf_block_size(void* ptr);
|
---|
70 |
|
---|
71 | /* Overheads/limits of internal structures. */
|
---|
72 | size_t tlsf_size(void);
|
---|
73 | size_t tlsf_align_size(void);
|
---|
74 | size_t tlsf_block_size_min(void);
|
---|
75 | size_t tlsf_block_size_max(void);
|
---|
76 | size_t tlsf_pool_overhead(void);
|
---|
77 | size_t tlsf_alloc_overhead(void);
|
---|
78 |
|
---|
79 | /* Debugging. */
|
---|
80 | typedef void (*tlsf_walker)(void* ptr, size_t size, int used, void* user);
|
---|
81 | void tlsf_walk_pool(pool_t pool, tlsf_walker walker, void* user);
|
---|
82 | /* Returns nonzero if any internal consistency check fails. */
|
---|
83 | int tlsf_check(tlsf_t tlsf);
|
---|
84 | int tlsf_check_pool(pool_t pool);
|
---|
85 |
|
---|
86 | #if defined(__cplusplus)
|
---|
87 | };
|
---|
88 | #endif
|
---|
89 |
|
---|
90 | #endif
|
---|