CMU15213 笔记:malloc
CMU15213 笔记:malloc
CS15-213 lab notes
sbrk
为了实现动态的内存分配,一个核心的函数就是 sbrk
memory alignment
8 字节对齐的地址特征,其地址数值的 16 进制表示的最后一个字符为 0。
以 8 字节对齐,可以使对 long,double 进行操作时,不会产生 bus error。
malloc is supposed to return a pointer “which is suitably aligned for any built-in type”.
allocator
需要处理以下问题:
数据结构
代码
定义一些必要的宏函数,如下所示
测试结果
Reference
- https://danluu.com/malloc-tutorial/