# manishcooks/grab architecture

> Architecture diagram of the GitHub repository manishcooks/grab, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/manishcooks/grab
- Repository: https://github.com/manishcooks/grab

## Overview

Grab is a small C++ allocator and multithreaded allocation benchmark. A user supplies a thread count; the benchmark starts and joins workers, each of which performs 100,000 allocations through its thread-local allocator. The allocator rounds small requests into size classes, reuses freed blocks, and obtains its pool with `mmap`. The README also describes a global-lock baseline, but the sampled runtime shows the thread-local design; no baseline implementation is present in the tree. Edges reflect the excerpts and README, not unsampled code.

Main entry points: [`grab.hpp`](https://github.com/manishcooks/grab/blob/main/grab.hpp) (Thread-local allocator), [`main.cpp`](https://github.com/manishcooks/grab/blob/main/main.cpp) (Benchmark driver)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_benchmark["Benchmark"]
  node_driver["Benchmark driver<br/>[main.cpp]"]
  node_worker["Allocation worker<br/>[main.cpp]"]
end

subgraph group_allocator["Allocator"]
  node_grab["Thread-local allocator<br/>[grab.hpp]"]
  node_freelists["Segregated free lists<br/>[grab.hpp]"]
  node_pool[("Mapped memory pool<br/>[grab.hpp]")]
end

node_user(("User"))
node_os["Operating system"]

node_user -->|"sets thread count"| node_driver
node_driver -->|"starts and joins"| node_worker
node_worker -->|"allocates 16 bytes"| node_grab
node_grab -->|"reuses blocks"| node_freelists
node_grab -->|"bumps allocation"| node_pool
node_grab -->|"maps and unmaps"| node_os

click node_driver "https://github.com/manishcooks/grab/blob/main/main.cpp"
click node_worker "https://github.com/manishcooks/grab/blob/main/main.cpp"
click node_grab "https://github.com/manishcooks/grab/blob/main/grab.hpp"
click node_freelists "https://github.com/manishcooks/grab/blob/main/grab.hpp"
click node_pool "https://github.com/manishcooks/grab/blob/main/grab.hpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_driver,node_worker,node_user toneBlue
class node_grab,node_freelists,node_pool toneAmber
class node_os toneIndigo
```

## Components

### Benchmark

- [Benchmark driver](https://github.com/manishcooks/grab/blob/main/main.cpp): `main.cpp`
- [Allocation worker](https://github.com/manishcooks/grab/blob/main/main.cpp): `main.cpp`

### Allocator

- [Thread-local allocator](https://github.com/manishcooks/grab/blob/main/grab.hpp): `grab.hpp`
- [Segregated free lists](https://github.com/manishcooks/grab/blob/main/grab.hpp): `grab.hpp`
- [Mapped memory pool](https://github.com/manishcooks/grab/blob/main/grab.hpp): `grab.hpp`

### Other components

- **User**
- **Operating system**

## Connections

- User → Benchmark driver: sets thread count (evidence: `main.cpp`)
- Benchmark driver → Allocation worker: starts and joins (evidence: `main.cpp`)
- Allocation worker → Thread-local allocator: allocates 16 bytes (evidence: `main.cpp`)
- Thread-local allocator → Segregated free lists: reuses blocks (evidence: `grab.hpp`)
- Thread-local allocator → Mapped memory pool: bumps allocation (evidence: `grab.hpp`)
- Thread-local allocator → Operating system: maps and unmaps (evidence: `grab.hpp`)
