c - What happens when there is a request for memory block which is not a power of 2? -
suppose malloc request memory block of size n 2 ^k !=n k>0. malloc returns space requestted memory block how remainig buffer handled page. read pages blocks of memory powers of two.
wiki states following:
method of memory allocation, heap become fragmented; is, there sections of used , unused memory in allocated space on heap. allocator attempt find unused area of allocated memory use before resorting expanding heap.
so question how tracked?
edit: how unused memory tracked when using malloc ?
this depends on specific implementation, morten siebuhr pointed out already. in simple cases, there might list of free, fixed-size blocks of memory (possibly having same size), unused memory wasted. note real implementations never use such simplistic algorithms.
this overview on simple possibilities: http://www.osdcom.info/content/view/31/39/
this wikipedia entry has several interesting links, including 1 above: http://en.wikipedia.org/wiki/dynamic_memory_allocation#implementations
as final remark, googling "malloc implementation" turns heap (pun intended) of valuable links.
Comments
Post a Comment