Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The implementation choices for a heap manager make a lot more sense when you consider what happens after a large number of allocations and deallocations. </p> <p>A call to <code>malloc()</code> needs to locate a block of unused block of sufficient size to allocate. It could be bigger (in which case, it could either create a free block with the difference - or waste it). A naive strategy of finding the closest size of block is called <em>best fit</em>. If it goes onto to create new free blocks, you could alternatively call it <em>worst leave</em>.</p> <p>After use, the best-fit approach results in a large amounts of fragmentation, caused by small blocks that are unlikely to be ever allocated again, and the cost of searching the free blocks becomes high. </p> <p>Consequently, high performance heap managers don't work like this. Instead they operate as pool allocators for various fixed block-sizes. Schemes in which the blocks are powers of 2 (e.g. <code>64,128,256,512...</code>) the norm, although throwing in some intermediates is probably worthwhile too (e.g. <code>48,96,192...)</code>. In this scheme, <code>malloc()</code> and <code>free()</code> are both <code>O(1)</code> operations, and the critical sections in allocation are minimal - potentially per pool - which gets important in a multi-threaded environment. </p> <p>The wasting of memory in small allocations is a much lesser evil than fragmentation, <code>O(n)</code> alloc\dealloc complexity and poor MT performance. </p> <p>The minimum block size w.r.t. to the cache line size is one of those classic engineering trade-offs, and it's a safe bet that Microsoft did quite a bit of experimentation to arrive at <code>64</code> as their minimum. FWIW, I'm pretty sure you'll find the cache-line size of modern CPUs are bigger than that. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload