| 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 | #include <QtCore/qtconfigmacros.h> |
| 44 | |
| 45 | QT_BEGIN_NAMESPACE |
| 46 | |
| 47 | namespace QtPrivate { |
| 48 | |
| 49 | /* tlsf_t: a TLSF structure. Can contain 1 to N pools. */ |
| 50 | /* pool_t: a block of memory that TLSF can manage. */ |
| 51 | typedef void* tlsf_t; |
| 52 | typedef void* pool_t; |
| 53 | |
| 54 | /* Create/destroy a memory pool. */ |
| 55 | tlsf_t tlsf_create(void* mem); |
| 56 | tlsf_t tlsf_create_with_pool(void* mem, size_t bytes); |
| 57 | void tlsf_destroy(tlsf_t tlsf); |
| 58 | pool_t tlsf_get_pool(tlsf_t tlsf); |
| 59 | |
| 60 | /* Add/remove memory pools. */ |
| 61 | pool_t tlsf_add_pool(tlsf_t tlsf, void* mem, size_t bytes); |
| 62 | void tlsf_remove_pool(tlsf_t tlsf, pool_t pool); |
| 63 | |
| 64 | /* malloc/memalign/realloc/free replacements. */ |
| 65 | void* tlsf_malloc(tlsf_t tlsf, size_t bytes); |
| 66 | void* tlsf_memalign(tlsf_t tlsf, size_t align, size_t bytes); |
| 67 | void* tlsf_realloc(tlsf_t tlsf, void* ptr, size_t size); |
| 68 | void tlsf_free(tlsf_t tlsf, void* ptr); |
| 69 | |
| 70 | /* Returns internal block size, not original request size */ |
| 71 | size_t tlsf_block_size(void* ptr); |
| 72 | |
| 73 | /* Overheads/limits of internal structures. */ |
| 74 | size_t tlsf_size(void); |
| 75 | size_t tlsf_align_size(void); |
| 76 | size_t tlsf_block_size_min(void); |
| 77 | size_t tlsf_block_size_max(void); |
| 78 | size_t tlsf_pool_overhead(void); |
| 79 | size_t tlsf_alloc_overhead(void); |
| 80 | |
| 81 | /* Debugging. */ |
| 82 | typedef void (*tlsf_walker)(void* ptr, size_t size, int used, void* user); |
| 83 | void tlsf_walk_pool(pool_t pool, tlsf_walker walker, void* user); |
| 84 | /* Returns nonzero if any internal consistency check fails. */ |
| 85 | int tlsf_check(tlsf_t tlsf); |
| 86 | int tlsf_check_pool(pool_t pool); |
| 87 | |
| 88 | } // namespace QtPrivate |
| 89 | |
| 90 | QT_END_NAMESPACE |
| 91 | |
| 92 | #endif |
| 93 | |