How can garbage collectors be faster than explicit memory deallocation?

后端 未结 4 466
遥遥无期
遥遥无期 2021-02-03 10:41

I was reading this html generated, (may expire, Here is the original ps file.)

GC Myth 3: Garbage collectors are always slower than explicit memory deallocation.
GC

4条回答
  •  一个人的身影
    2021-02-03 11:21

    How would GC be faster then explicit memory deallocation?

    1. GCs can pointer-bump allocate into a thread-local generation and then rely upon copying collection to handle the (relatively) uncommon case of evacuating the survivors. Traditional allocators like malloc often compete for global locks and search trees.

    2. GCs can deallocate many dead blocks simultaneously by resetting the thread-local allocation buffer instead of calling free on each block in turn, i.e. O(1) instead of O(n).

    3. By compacting old blocks so more of them fit into each cache line. The improved locality increases cache efficiency.

    4. By taking advantage of extra static information such as immutable types.

    5. By taking advantage of extra dynamic information such as the changing topology of the heap via the data recorded by the write barrier.

    6. By making more efficient techniques tractable, e.g. by removing the headache of manual memory management from wait free algorithms.

    7. By deferring deallocation to a more appropriate time or off-loading it to another core. (thanks to Andrew Hill for this idea!)

提交回复
热议问题