Memory Allocation Strategies
1. Memory  mem
properties
ID: e485721a-4cd8-4bae-8d62-45e11729da70CREATED: <2025-02-13 Thu 22:27>
1.1. Memory Pool  alloc
properties
ID: 2ae80374-cb47-494a-be51-e7f267f80a99CREATED: <2025-02-13 Thu 22:31>
1.2. Buddy Allocator  alloc
properties
ID: 2f1f89cb-1b42-4155-b79e-b531659323afCREATED: <2025-02-13 Thu 22:28>
1.3. Bump Allocator
properties
ID: 5ce30140-63e4-44de-b1a2-aeca8d967075CREATED: <2025-06-03 Tue 22:00>
-
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
properties
ID: 613d9983-6681-4bf7-a99f-c098163f655cCREATED: <2025-06-03 Tue 21:59>
1.5. Garbage Collection  gc
properties
ID: e87b4de2-e614-484b-a4ef-97d1180f1bd0CREATED: <2025-06-03 Tue 21:59>
1.6. Arena Allocator  alloc arena
properties
ID: e6c79b21-6762-48e4-9168-d314c5761f8fCREATED: <2025-06-02 Mon 21:51>
1.7. Boundary Detection
properties
ID: a6957fbd-69a1-4123-bf2d-31b98c38be02CREATED: <2025-06-03 Tue 19:33>
1.7.1. Watchpoints
properties
ID: 0494bab0-8676-472a-8eaa-1cff42b932d0CREATED: <2025-06-03 Tue 19:40>
- Hardware Breakpoint (or watchpoint) usage in Linux Kernel
-
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
properties
ID: 4d872f6f-61a0-42d5-a5c9-5325bd8f184cCREATED: <2025-06-03 Tue 21:52>
1.8. Tagged Pointers
properties
ID: 03c44887-96f5-466a-8d42-7df51fd42eb5CREATED: <2025-06-03 Tue 21:50>
1.9. NaN Boxing
properties
ID: cffc8c70-d0bb-4af9-9b1c-f9fd7c5b081cCREATED: <2025-06-03 Tue 21:50>
- Dynamic Typing and NaN Boxing
- NaN boxing allows you to cram extra information into the NaN value that exists within the floating-point spectrum of numbers.
- the secret life of NaN
1.10. Fragmentation
properties
ID: eabf2d7b-c99f-4854-a64c-397ff8f90a2bCREATED: <2025-06-03 Tue 22:02>