How2heap总结
first-fit 如果一个chunk可用且足够大,那么就会使用这个chunk。 calc_tcache_idx tcache(thread local caching) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 /* We want 64 entries. This is an arbitrary limit, which tunables can reduce. */ # define TCACHE_MAX_BINS 64 # define MAX_TCACHE_SIZE tidx2usize (TCACHE_MAX_BINS-1) /* Only used to pre-fill the tunables. */ # define tidx2usize(idx) (((size_t) idx) * MALLOC_ALIGNMENT + MINSIZE - SIZE_SZ) /* When "x" is from chunksize(). */ # define csize2tidx(x) (((x) - MINSIZE + MALLOC_ALIGNMENT - 1) / MALLOC_ALIGNMENT) /* When "x" is a user-provided size. */ # define usize2tidx(x) csize2tidx (request2size (x)) /* With rounding and alignment, the bins are... idx 0 bytes 0..24 (64-bit) or 0..12 (32-bit) idx 1 bytes 25..40 or 13..20 idx 2 bytes 41..56 or 21..28 etc. */ tcache拥有和fastbin差不多的结构。默认情况下,64个bin,每个bin最多7个chunk 64bit: IDX = (CHUNKSIZE - 0x11) / 0x10 ...