🧮 Heap Allocator Visualization

Interactive demonstration of heap memory allocation strategies from CS107 Stanford

CS107 Systems Programming Memory Management
bytes
Heap View
Free List Structure
Statistics
Learn
Heap Memory Layout
Free Block
Allocated Block

âš ī¸ Key Differences

Feature Implicit Explicit
Footer None Free blocks only
Coalescing NO coalescing Immediate on free
Free list Linear scan Doubly-linked
Find fit O(n) all blocks O(f) free blocks
Free List Chain (Explicit Implementation)

â„šī¸ About Free Lists

Implicit Free List: Free blocks are found by linear scan through all blocks.

Explicit Free List: Free blocks are linked together using next/prev pointers stored in the payload area, enabling O(1) coalescing with footers.

Total Heap Size
512
bytes
Allocated
0
bytes
Free
512
bytes
Fragmentation
0
%
Free Blocks
1
blocks
Allocations
0
total

📊 Performance Metrics

Fragmentation: Percentage of free memory that cannot be used due to being split into small, non-contiguous blocks.

Coalescing: Merging adjacent free blocks to reduce fragmentation (explicit allocator only).

Note: Implicit allocator has NO coalescing - free blocks remain separate!

📚 Key Concepts

  • 8-byte Alignment: All blocks are aligned to 8-byte boundaries for performance (ALIGNMENT = 8).
  • Headers: Each block has a header containing size and allocation status (size_t).
  • Implicit Allocator: NO coalescing, NO footer, uses linear scan O(n) to find free blocks.
  • Explicit Allocator: Has footer for free blocks, immediate coalescing, doubly-linked free list O(1).
  • Splitting: Large free blocks are split if remainder >= minimum block size.
  • First-fit: Allocator searches from the beginning and uses the first suitable block.

đŸŽ¯ CS107 Implementation Details

This visualization demonstrates the concepts from CS107 Assignment 6:

  • Implicit: Header-only, no coalescing, linear search through all blocks
  • Explicit: Header + footer (for free blocks), immediate coalescing on free
  • Free List: Explicit uses doubly-linked list with prev/next pointers in payload
  • Minimum block size: 16 bytes (header + minimum payload)
  • Bit flags: ALLOC_BIT (0x1 implicit, 0x2 explicit), LEFT_ALLOC_BIT (0x4 explicit only)

📚 Educational Purpose Only

This visualization is designed for educational and learning purposes only. It demonstrates the conceptual differences between implicit and explicit heap allocators as taught in Stanford CS107.

Note: This is a simplified visualization of memory allocation concepts. Actual implementation code is not provided to maintain academic integrity. Students should implement their own allocators based on course specifications.

Created by Xuming Huang | CS107 Stanford Summer 2024 | Grade: A+ (99/100)