2 Two-Level Segregated Fit memory allocator implementation.
3 Written by Matthew Conte (matt@baisoku.org).
4 Released under the BSD license.
8 * O(1) cost for malloc, free, realloc, memalign
9 * Extremely low overhead per allocation (4 bytes)
10 * Low overhead per TLSF management of pools (~3kB)
12 * Compiles to only a few kB of code and data
13 * Support for adding and removing memory pool regions on the fly
17 * Currently, assumes architecture can make 4-byte aligned accesses
18 * Not designed to be thread safe; the user must provide this
22 This code was based on the TLSF 1.4 spec and documentation found at:
24 http://www.gii.upv.es/tlsf/main/docs
26 It also leverages the TLSF 2.0 improvement to shrink the per-block overhead from 8 to 4 bytes.
31 * Code moved to github
32 * tlsfbits.h rolled into tlsf.c
33 * License changed to BSD
36 * This version is based on improvements from 3DInteractive GmbH
37 * Interface changed to allow more than one memory pool
38 * Separated pool handling from control structure (adding, removing, debugging)
39 * Control structure and pools can still be constructed in the same memory block
40 * Memory blocks for control structure and pools are checked for alignment
41 * Added functions to retrieve control structure size, alignment size, min and max block size, overhead of pool structure, and overhead of a single allocation
42 * Minimal Pool size is tlsf_block_size_min() + tlsf_pool_overhead()
43 * Pool must be empty when it is removed, in order to allow O(1) removal
47 * More compiler intrinsics for ffs/fls
48 * ffs/fls verification during TLSF creation in debug builds
51 * Add tlsf_heap_check, a heap integrity check
52 * Support a predefined tlsf_assert macro
53 * Fix realloc case where block should shrink; if adjacent block is in use, execution would go down the slow path
56 * Fix for unnecessary reallocation in tlsf_realloc
59 * tlsf_heap_walk takes a callback
60 * tlsf_realloc now returns NULL on failure
61 * tlsf_memalign optimization for 4-byte alignment
62 * Usage of size_t where appropriate
65 * ffs/fls broken out into tlsfbits.h
66 * tlsf_overhead queries per-pool overhead
69 * Smart realloc implementation
70 * Smart memalign implementation
73 * Add some ffs/fls implementations
74 * Minor code footprint reduction
77 * Profiling indicates heavy use of blocks of size 1-128, so implement small block handling
78 * Reduce pool overhead by about 1kb
79 * Reduce minimum block size from 32 to 12 bytes
84 * Static assertion mechanism for invariants