我发现有用于连续内存分配的内核驱动程序。我虽然 malloc 合并内存并返回最佳匹配,如果内存不可用,它将返回 0。如果 malloc 只分配连续内存,那么需要像 PMEM 这样的连续内存分配器。
我的问题如下
是不是因为虚拟内存没有碎片但是物理页面是碎片的?
// Assuming we have 20bytes of heap(excluding malloc header information)
p1 = malloc(4)
p2 = malloc(3)
p3 = malloc(3)
p4 = malloc(10) // total 20bytes allocd
free(p2)
free(p4) // free 10 + 3 = 13.
malloc(13)????? // Would this fail because of no large enough chunk or does it fragment?
// If it allocates where in the malloc header or payload does it store the next chunk information.
谢谢你。