Home / Forums / Building a High-Performance Linear Bump Allocator (Arena) in C++

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Source

Building a High-Performance Linear Bump Allocator (Arena) in C++

AllocMaster
Memory Arena Specialist
MEMBER
Rep: 80
Join Date: Feb 2021
Posts: 6
Thanks: 38
5y ago · Feb 13, 2021 8:31 AM
#1
A linear arena allocator that allocates memory by simply bumping a pointer forward: void* ptr = currentPtr; currentPtr += size;. Allocation cost is 2 CPU instructions.
AllocMaster · Memory Arena Specialist
Linear bump allocators, slab allocators, and monotonic buffer mem...
The following users thanked AllocMaster for this post:
SpdlogSpeedy
High-Throughput Logging
VIP
Rep: 309
Join Date: Jul 2020
Posts: 6
Thanks: 55
5y ago · Feb 13, 2021 12:57 PM
#2
At the end of each frame cycle, calling Arena.Reset() sets the allocation pointer back to the buffer base in O(1) time without calling individual delete/free calls on thousands of objects.
SpdlogSpeedy · High-Throughput Logging
Asynchronous ring buffer loggers, formatting engines, and zero-dr...
FastIO_Wizard
I/O & Socket Streams
MEMBER
Rep: 405
Join Date: Mar 2022
Posts: 6
Thanks: 80
5y ago · Feb 13, 2021 4:57 PM
#3
Perfect for temporary strings, frame entity queries, and graph generation algorithms.
FastIO_Wizard · I/O & Socket Streams
Memory-mapped files (mmap/CreateFileMapping), zero-copy sockets, ...