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