title: Best heuristic for malloc
body: <p>Consider using malloc() to allocate x bytes of memory in a fragmented heap. Assume the heap has multiple contiguous locations of size greater than x bytes. </p>
  
  <p>Which is the best (that leads to least heap wastage) heuristic to choose a location among the following?</p>
  
  <ol>
  <li>Select smallest location that is bigger than x bytes.</li>
  <li>Select largest location that is bigger than x bytes.</li>
  </ol>
  
  <p>My intuition is smallest location that is bigger than x bytes. I am not sure which is the best in practice. </p>
  
  <p>No, this is not any assignment question. I was reading this <a href="https://stackoverflow.com/questions/1119134/how-malloc-and-free-work">How do malloc() and free() work?</a> and this looks like a good follow up question to ask.</p>