# aryan9787/myalloc architecture

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

- Interactive diagram: https://gitdiagram.com/aryan9787/myalloc
- Repository: https://github.com/aryan9787/myalloc

## Overview

myAlloc is an educational C allocator exposing `an_malloc()` and `an_free()`. Callers enter through the public API; allocation initializes the process heap if needed, aligns the request, and delegates block selection and allocation. Freeing validates and releases a block, coalesces adjacent free space, then attempts to shrink the heap. The implementation uses block metadata, `sbrk()`, and a lock. The README documents these capabilities; the graph’s call edges are based on the excerpted source, not unsampled files.

Main entry points: [`src/allocator.c`](https://github.com/aryan9787/myalloc/blob/main/src/allocator.c) (Allocate and free), [`src/block.c`](https://github.com/aryan9787/myalloc/blob/main/src/block.c) (Block operations), [`src/heap.c`](https://github.com/aryan9787/myalloc/blob/main/src/heap.c) (Heap management), [`include/allocator.h`](https://github.com/aryan9787/myalloc/blob/main/include/allocator.h) (Allocator API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Public API"]
  node_public_api["Allocator API<br/>[allocator.h]"]
  node_entrypoints["Allocate and free<br/>[allocator.c]"]
end

subgraph group_blocks["Block Management"]
  node_metadata["Heap metadata"]
  node_block_ops["Block operations<br/>[block.c]"]
end

subgraph group_runtime["Heap Runtime"]
  node_heap_ops["Heap management<br/>[heap.c]"]
  node_locking["Heap locking<br/>[sync.c]"]
end

node_callers(("Allocator callers"))
node_process_heap[("Process heap")]

node_callers -->|"calls"| node_public_api
node_public_api -->|"exposes"| node_entrypoints
node_entrypoints -->|"aligns and initializes"| node_heap_ops
node_entrypoints -->|"allocates and validates"| node_block_ops
node_entrypoints -->|"locks heap"| node_locking
node_entrypoints -->|"shrinks after free"| node_heap_ops
node_block_ops -->|"extends heap"| node_heap_ops
node_block_ops -->|"locks heap"| node_locking
node_heap_ops -->|"finds prior block"| node_block_ops
node_entrypoints -->|"requests pages"| node_process_heap
node_block_ops -->|"requests pages"| node_process_heap
node_heap_ops -->|"releases pages"| node_process_heap

click node_public_api "https://github.com/aryan9787/myalloc/blob/main/include/allocator.h"
click node_entrypoints "https://github.com/aryan9787/myalloc/blob/main/src/allocator.c"
click node_metadata "https://github.com/aryan9787/myalloc/blob/main/include/allocator_internal.h"
click node_block_ops "https://github.com/aryan9787/myalloc/blob/main/src/block.c"
click node_heap_ops "https://github.com/aryan9787/myalloc/blob/main/src/heap.c"
click node_locking "https://github.com/aryan9787/myalloc/blob/main/src/sync.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_public_api,node_entrypoints toneBlue
class node_metadata,node_block_ops,node_process_heap toneAmber
class node_heap_ops,node_locking toneMint
class node_callers toneIndigo
```

## Components

### Public API

- [Allocator API](https://github.com/aryan9787/myalloc/blob/main/include/allocator.h): `include/allocator.h`
- [Allocate and free](https://github.com/aryan9787/myalloc/blob/main/src/allocator.c): `src/allocator.c`

### Block Management

- [Heap metadata](https://github.com/aryan9787/myalloc/blob/main/include/allocator_internal.h): `include/allocator_internal.h`
- [Block operations](https://github.com/aryan9787/myalloc/blob/main/src/block.c): `src/block.c`

### Heap Runtime

- [Heap management](https://github.com/aryan9787/myalloc/blob/main/src/heap.c): `src/heap.c`
- [Heap locking](https://github.com/aryan9787/myalloc/blob/main/src/sync.c): `src/sync.c`

### Other components

- **Allocator callers**
- **Process heap**

## Connections

- Allocator callers → Allocator API: calls (evidence: `include/allocator.h`)
- Allocator API → Allocate and free: exposes (evidence: `include/allocator.h`)
- Allocate and free → Heap management: aligns and initializes (evidence: `src/allocator.c`)
- Allocate and free → Block operations: allocates and validates (evidence: `src/allocator.c`)
- Allocate and free → Heap locking: locks heap (evidence: `src/allocator.c`)
- Allocate and free → Heap management: shrinks after free (evidence: `src/allocator.c`)
- Block operations → Heap management: extends heap (evidence: `src/block.c`)
- Block operations → Heap locking: locks heap (evidence: `src/block.c`)
- Heap management → Block operations: finds prior block (evidence: `src/heap.c`)
- Allocate and free → Process heap: requests pages (evidence: `src/allocator.c`)
- Block operations → Process heap: requests pages (evidence: `src/block.c`)
- Heap management → Process heap: releases pages (evidence: `src/heap.c`)
