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
typedef struct block
{
word_t header;//包含1bit的是否分配、剩下的表示payload大小
un

这篇博客详细介绍了 CMU 15213 课程中的 malloc 笔记,涵盖了动态内存分配的基础概念、显式分配器的工作原理,包括隐式空闲链表、显式空闲链表(如 LIFO 和 FIFO 策略)和 Segregated List。还探讨了隐式内存管理,即垃圾收集,以及如何通过有向图标记法来判断内存是否可释放。在malloc实验部分,文章提到了不同策略实现的效果,如显式链表的分数对比。
最低0.47元/天 解锁文章
5753

被折叠的 条评论
为什么被折叠?



