Memory Allocation Strategies

1. Memory   mem

ID: e485721a-4cd8-4bae-8d62-45e11729da70
CREATED: <2025-02-13 Thu 22:27>

1.1. Memory Pool   alloc

ID: 2ae80374-cb47-494a-be51-e7f267f80a99
CREATED: <2025-02-13 Thu 22:31>

[2025-02-13 Thu 22:32] Writing a simple pool allocator in C [2025-02-13 Thu 22:32] Memory pool - Wikipedia

1.2. Buddy Allocator   alloc

ID: 2f1f89cb-1b42-4155-b79e-b531659323af
CREATED: <2025-02-13 Thu 22:28>

[2025-02-13 Thu 22:29] How to implement a Buddy allocator

1.3. Bump Allocator

ID: 5ce30140-63e4-44de-b1a2-aeca8d967075
CREATED: <2025-06-03 Tue 22:00>
  • bumpalo - Rust

    We have a chunk of memory, and we maintain a pointer within that memory. Whenever we allocate an object, we do a quick check that we have enough capacity left in our chunk to allocate the object and then update the pointer by the object’s size. That’s it!

    The disadvantage of bump allocation is that there is no general way to deallocate individual objects or reclaim the memory region for a no-longer-in-use object.

1.4. Reference Counting

ID: 613d9983-6681-4bf7-a99f-c098163f655c
CREATED: <2025-06-03 Tue 21:59>

[2025-06-03 Tue 21:59] wiki

1.5. Garbage Collection   gc

ID: e87b4de2-e614-484b-a4ef-97d1180f1bd0
CREATED: <2025-06-03 Tue 21:59>

1.6. Arena Allocator   alloc arena

ID: e6c79b21-6762-48e4-9168-d314c5761f8f
CREATED: <2025-06-02 Mon 21:51>

[2025-06-02 Mon 22:13] <- Arenas [2025-06-03 Tue 21:58] Region-based memory management

1.7. Boundary Detection

ID: a6957fbd-69a1-4123-bf2d-31b98c38be02
CREATED: <2025-06-03 Tue 19:33>

1.7.1. Watchpoints

ID: 0494bab0-8676-472a-8eaa-1cff42b932d0
CREATED: <2025-06-03 Tue 19:40>
  • Hardware Breakpoint (or watchpoint) usage in Linux Kernel
  • mutablecode - watchpoints

    Watchpoint-based bounds checking does offer free performance, but comes with list of exceptions and conditions:

    Watchpoints are dependent on both the processor and operating system: the hardware must have the feature, and the software must expose it

    When they are supported, setup may be slow (eg many system calls) or impose other requirements (eg forking on Linux)

    Each side of a boundary check requires one watchpoint, of which there are relatively few (4 on x86, 16 on Arm)

    Each end must also be padded by at least a word; memory before and after an array are used validly elsewhere

    Only the boundary is checked: jumping past watchpoints is undetectable

    When errors are detected, signal-driven logic makes graceful recovery difficult

    Using a debugger is also difficult, as they too use the watchpoints

    They add complexity

    This list is not exhaustive; it shows watchpoints are nuanced and require careful thought and planning for correct usage.

    Looking forward, compilers could treat watchpoints like another register resource, automatically using them for bounds checking and other creative uses. Beyond twisting them into bounds checkers, watchpoints are more commonly found in debuggers like lldb and gdb, although a program could provide its own debugging capabilities; the example code is essentially the skeleton of a debugger.

1.7.2. Guard Pages

ID: 4d872f6f-61a0-42d5-a5c9-5325bd8f184c
CREATED: <2025-06-03 Tue 21:52>

1.8. Tagged Pointers

ID: 03c44887-96f5-466a-8d42-7df51fd42eb5
CREATED: <2025-06-03 Tue 21:50>

1.9. NaN Boxing

ID: cffc8c70-d0bb-4af9-9b1c-f9fd7c5b081c
CREATED: <2025-06-03 Tue 21:50>

1.10. Fragmentation

ID: eabf2d7b-c99f-4854-a64c-397ff8f90a2b
CREATED: <2025-06-03 Tue 22:02>

[2025-06-03 Tue 22:02] wiki