123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- /*
- ** Two Level Segregated Fit memory allocator, version 3.1.
- ** Written by Matthew Conte
- ** http://tlsf.baisoku.org
- **
- ** Based on the original documentation by Miguel Masmano:
- ** http://www.gii.upv.es/tlsf/main/docs
- **
- ** This implementation was written to the specification
- ** of the document, therefore no GPL restrictions apply.
- **
- ** Copyright (c) 2006-2016, Matthew Conte
- ** All rights reserved.
- **
- ** Redistribution and use in source and binary forms, with or without
- ** modification, are permitted provided that the following conditions are met:
- ** * Redistributions of source code must retain the above copyright
- ** notice, this list of conditions and the following disclaimer.
- ** * Redistributions in binary form must reproduce the above copyright
- ** notice, this list of conditions and the following disclaimer in the
- ** documentation and/or other materials provided with the distribution.
- ** * Neither the name of the copyright holder nor the
- ** names of its contributors may be used to endorse or promote products
- ** derived from this software without specific prior written permission.
- **
- ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- ** DISCLAIMED. IN NO EVENT SHALL MATTHEW CONTE BE LIABLE FOR ANY
- ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- #pragma once
- enum tlsf_config
- {
- /* log2 of number of linear subdivisions of block sizes. Larger
- ** values require more memory in the control structure. Values of
- ** 4 or 5 are typical, 3 is for very small pools.
- */
- SL_INDEX_COUNT_LOG2_MIN = 3,
- /* All allocation sizes and addresses are aligned to 4 bytes. */
- ALIGN_SIZE_LOG2 = 2,
- ALIGN_SIZE = (1 << ALIGN_SIZE_LOG2),
- /*
- ** We support allocations of sizes up to (1 << FL_INDEX_MAX) bits.
- ** However, because we linearly subdivide the second-level lists, and
- ** our minimum size granularity is 4 bytes, it doesn't make sense to
- ** create first-level lists for sizes smaller than SL_INDEX_COUNT * 4,
- ** or (1 << (SL_INDEX_COUNT_LOG2 + 2)) bytes, as there we will be
- ** trying to split size ranges into more slots than we have available.
- ** Instead, we calculate the minimum threshold size, and place all
- ** blocks below that size into the 0th first-level list.
- ** Values below are the absolute minimum to accept a pool addition
- */
- FL_INDEX_MAX_MIN = 14, // For a less than 16kB pool
- SL_INDEX_COUNT_MIN = (1 << SL_INDEX_COUNT_LOG2_MIN),
- FL_INDEX_COUNT_MIN = (FL_INDEX_MAX_MIN - (SL_INDEX_COUNT_LOG2_MIN + ALIGN_SIZE_LOG2) + 1),
- };
|