当存储块请求不是2的幂时会发生什么?

Pra*_*n S 6 c linux malloc

假设我们对大小为n的内存块执行malloc请求,其中k ^ 0为2 ^ k!= n.Malloc为请求的内存块返回空间,但是如何从页面处理stillig缓冲区.我读过Pages通常是内存块,它们是2的幂.

Wiki声明如下:

 Like any method of memory allocation, the heap will become fragmented; that is,
 there will be sections of used and unused memory in the allocated 
 space on the heap. A good allocator will attempt to find an unused area
 of already allocated memory to use before resorting to expanding the heap.
Run Code Online (Sandbox Code Playgroud)

所以我的问题是如何追踪?

编辑:使用malloc时如何跟踪未使用的内存?

Gre*_*g S 3

正如 Morten Siebuhr 已经指出的那样,这实际上取决于具体的实施。在非常简单的情况下,可能存在一个空闲的、固定大小的内存块列表(可能全部具有相同的大小),因此未使用的内存只是被浪费了。请注意,真正的实现永远不会使用如此简单的算法。

这是对一些简单可能性的概述:http://www.osdcom.info/content/view/31/39/

此维基百科条目有几个有趣的链接,包括上面的链接:http ://en.wikipedia.org/wiki/Dynamic_memory_allocation#Implementations

最后说一句,谷歌搜索“malloc实现”会发现一堆有价值的链接(双关语)。