heap_tlsf_config.h 3.0 KB

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