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

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -