Heap Management

1. Heap Allocation

The heap is managed in blocks, which contain:

Object references point to the object data, not the start of the block.

Traditional heap allocation is managed by a free list, a chain of free blocks in the heap. Each heap block contains tracking info in the housekeeping data section. We check in this order:

  1. If a free block of exactly the correct size is found, return it.
  2. If a block bigger than the requested size is found, split it into two blocks: one of the requested size, and the other with the remaining size.
  3. If no block is found, request more memory from the OS.

However, this algorithm is quite slow. We could:

We also need to consider memory alignment and negative impact on caching when we dont have spacial locality.

2. Garbage Collection

We can automatically deallocate from the heap with garbage collection. This could be done by:

Back to Home