# rn-ops/memory-allocator-in-c architecture

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

- Interactive diagram: https://gitdiagram.com/rn-ops/memory-allocator-in-c
- Repository: https://github.com/rn-ops/memory-allocator-in-c

## Overview

This is a cross-platform, page-backed C allocator intended to provide malloc, calloc, realloc, and free. The principal workflow enters through the allocator API, which looks for a free block or requests page-aligned memory from the OS layer, then returns a user pointer; calloc and realloc reuse allocator operations. Block metadata and the explicit free list support allocation and release. The README marks several allocator features as in progress, and the excerpts do not show how platform backends are selected or resolve a mismatch between the allocator’s free-list lookup and the provided implementation.

Main entry points: [`src/allocator.c`](https://github.com/rn-ops/memory-allocator-in-c/blob/main/src/allocator.c) (Allocation runtime), [`src/os/os.h`](https://github.com/rn-ops/memory-allocator-in-c/blob/main/src/os/os.h) (OS memory interface), [`include/allocator.h`](https://github.com/rn-ops/memory-allocator-in-c/blob/main/include/allocator.h) (Public allocator interface), [`src/block.c`](https://github.com/rn-ops/memory-allocator-in-c/blob/main/src/block.c) (Block metadata)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Allocator API"]
  node_allocator["Allocation runtime<br/>[allocator.c]"]
  node_header["Public allocator interface<br/>[allocator.h]"]
end

subgraph group_memory["Block Management"]
  node_block["Block metadata<br/>[block.c]"]
  node_free_list["Explicit free list<br/>[free_list.c]"]
  node_utils["Alignment utilities<br/>[utils.c]"]
end

subgraph group_platform["OS Abstraction"]
  node_os_interface["OS memory interface<br/>[os.h]"]
  node_linux["Linux backend<br/>[linux.c]"]
  node_windows["Windows backend<br/>[windows.c]"]
end

node_caller(("Allocator caller"))

node_caller -->|"calls allocation API"| node_allocator
node_allocator -->|"uses block definitions"| node_header
node_allocator -->|"requests pages"| node_os_interface
node_allocator -->|"initializes and checks"| node_block
node_allocator -->|"searches and updates"| node_free_list
node_allocator -->|"reuses allocation operations"| node_allocator
node_os_interface -.->|"dispatches on Linux"| node_linux
node_os_interface -.->|"dispatches on Windows"| node_windows

click node_allocator "https://github.com/rn-ops/memory-allocator-in-c/blob/main/src/allocator.c"
click node_header "https://github.com/rn-ops/memory-allocator-in-c/blob/main/include/allocator.h"
click node_block "https://github.com/rn-ops/memory-allocator-in-c/blob/main/src/block.c"
click node_free_list "https://github.com/rn-ops/memory-allocator-in-c/blob/main/src/free_list.c"
click node_utils "https://github.com/rn-ops/memory-allocator-in-c/blob/main/src/utils.c"
click node_os_interface "https://github.com/rn-ops/memory-allocator-in-c/blob/main/src/os/os.h"
click node_linux "https://github.com/rn-ops/memory-allocator-in-c/blob/main/src/os/linux.c"
click node_windows "https://github.com/rn-ops/memory-allocator-in-c/blob/main/src/os/windows.c"

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_allocator,node_header toneBlue
class node_block,node_free_list,node_utils toneAmber
class node_os_interface,node_linux,node_windows toneMint
class node_caller toneIndigo
```

## Components

### Allocator API

- [Allocation runtime](https://github.com/rn-ops/memory-allocator-in-c/blob/main/src/allocator.c): `src/allocator.c`
- [Public allocator interface](https://github.com/rn-ops/memory-allocator-in-c/blob/main/include/allocator.h): `include/allocator.h`

### Block Management

- [Block metadata](https://github.com/rn-ops/memory-allocator-in-c/blob/main/src/block.c): `src/block.c`
- [Explicit free list](https://github.com/rn-ops/memory-allocator-in-c/blob/main/src/free_list.c): `src/free_list.c`
- [Alignment utilities](https://github.com/rn-ops/memory-allocator-in-c/blob/main/src/utils.c): `src/utils.c`

### OS Abstraction

- [OS memory interface](https://github.com/rn-ops/memory-allocator-in-c/blob/main/src/os/os.h): `src/os/os.h`
- [Linux backend](https://github.com/rn-ops/memory-allocator-in-c/blob/main/src/os/linux.c): `src/os/linux.c`
- [Windows backend](https://github.com/rn-ops/memory-allocator-in-c/blob/main/src/os/windows.c): `src/os/windows.c`

### Other components

- **Allocator caller**

## Connections

- Allocator caller → Allocation runtime: calls allocation API (evidence: `README.md`)
- Allocation runtime → Public allocator interface: uses block definitions (evidence: `src/allocator.c`)
- Allocation runtime → OS memory interface: requests pages (evidence: `src/allocator.c`)
- Allocation runtime → Block metadata: initializes and checks (evidence: `src/allocator.c`)
- Allocation runtime → Explicit free list: searches and updates (evidence: `src/allocator.c`)
- Allocation runtime → Allocation runtime: reuses allocation operations (evidence: `src/allocator.c`)
- OS memory interface → Linux backend: dispatches on Linux (evidence: `README.md`)
- OS memory interface → Windows backend: dispatches on Windows (evidence: `README.md`)
