Skip to main content
Be Bitwise

Bump Allocator

A simple bump allocator allocates objects at consecutive heap addresses by advancing a free pointer.

A bump allocator is the simplest possible memory allocator. It maintains a single 'free pointer' that starts at the beginning of free memory. Each allocation advances the pointer by the requested size, handing out consecutive memory regions. It is fast (O(1) per allocation) but cannot free individual objects — once allocated, memory can only be reclaimed by resetting the entire pointer. Real allocators (malloc, jemalloc) are much more complex because they need to support individual frees.

Simulator

Loading simulator...

Walkthrough Guide

  1. 1

    Initialise the free pointer

    Do this: Step through MOV R0, #128

    Watch for: R0 = 128. This is the start of our 'heap' region

    The free pointer starts at address 128 (0x80). The program's own instructions sit below it, so the heap starts above them. R0 will track where the next allocation goes.

  2. 2

    Allocate object A (2 bytes)

    Do this: Step through the two STORE instructions and ADD R0, #1 calls for object A

    Watch for: Values 10, 11 appear at addresses 128, 129. R0 advances to 130

    Object A occupies addresses 128-129. After writing its fields, the free pointer advances to 130 — the next free address. The allocator 'remembers' where free space starts by keeping R0 updated.

  3. 3

    Allocate objects B and C

    Do this: Step through the remaining STORE/ADD sequences

    Watch for: Object B at addresses 130-131 (values 12, 13). Object C at addresses 132-133 (values 14, 15). R0 ends at 134

    Each allocation simply advances the free pointer. Objects are packed contiguously with no gaps. This is very memory-efficient but offers no way to free object B without also losing C.

Objectives

  • •Watch the free pointer (R0) advance from 128 to 134
  • •See objects placed at consecutive addresses: A at 128-129, B at 130-131, C at 132-133
  • •Notice each allocation just advances the pointer - no gaps, no reuse
  • •Understand why this simple allocator cannot reclaim freed memory

Hints

  • R0 acts as both the allocator's state and the current write address - it only moves forward