https://github.com/alberto-lazari/grain
C++ memory manager for grain-sized objects
https://github.com/alberto-lazari/grain
cmake cpp-library cpp20 memory-allocator memory-management modern-cpp small-object-optimization
Last synced: 4 months ago
JSON representation
C++ memory manager for grain-sized objects
- Host: GitHub
- URL: https://github.com/alberto-lazari/grain
- Owner: alberto-lazari
- Created: 2025-08-16T14:58:58.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2025-08-16T16:52:09.000Z (5 months ago)
- Last Synced: 2025-08-16T17:19:19.291Z (5 months ago)
- Topics: cmake, cpp-library, cpp20, memory-allocator, memory-management, modern-cpp, small-object-optimization
- Language: C++
- Homepage:
- Size: 32.2 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# 🌾 Grain
A C++ memory manager for grain-sized objects.
Developed as final project of the *Advanced C++* course for the Master in Computer Game Development.
## Overview
The project is based on Andrei Alexandrescu's `SmallObjectAllocator`,
described in his *Modern C++ Design* book.
The generic, long names he used in his implementation looked pretty ugly to me,
so I decided to give them a farming twist,
mapping each to a concrete item related to grains of wheat:
| Name | Analogy | Original Name |
| --------- | ---------------------------------------- | ---------------------- |
| `Granary` | Main storage of different kinds of grain | `SmallObjectAllocator` |
| `Sack` | Set of grains of the same kind (size) | `FixedAllocator` |
| `Handful` | A small handful of grains | `Chunk` |
| `Grain` | Smallest distributable unit | Memory block |
> [!NOTE]
> I'm well aware that this entire *grain metaphor*-thing makes the code pretty unreadable,
> but readability and usability in general are really not the point here.
>
> This is a simple University project, aiming to replicate an existing implementation,
> and is obviously not meant to appear in real-world codebases.
> I just wanted to have some fun while working on it.
## Build and Test
The project comes with a cross-platform CMake configuration.
You can build the project from the command line or open it as a folder in Visual Studio,
leaving it to the IDE to automatically load the targets.
Tests are split into separate executables that you can run from the CMake targets. \
On POSIX you can run them all with a simple `make test`.