1. malloc笔记
1.1 基础概念
1.dynamic memory allocators:应用程序运行期间申请的内存(malloc)。
2.堆:dynamic memory allocator管理的进程内存区域
3.types of allocator:隐式分配器(new and garbage collection)和显示分配器(malloc & free)
1.2 explicit allocator
1.malloc、free、realloc
2.16-byte (x86-64) alignment on 64-bit systems
3.内部碎片产生的原因:
- 维持堆所需的数据结构开销
- 对齐的需要
- 分配器实现的策略(比如,to return a big block to satisfy a small request)
4.外部碎片:Occurs when there is enough aggregate heap memory, but no single free block is large enough。(大块被划分成小块,虽然整个空闲内存能够放下程序,但是找不到单独的一块去存放)
5.keep track of free blocks:显式、隐式链表、Segregated free list(Different free lists for different size classes)、Blocks sorted by size(红黑树,长度为key)
1.2.1 隐式空闲链表
1.block structures