# edaywalid/memalloc architecture

> Architecture diagram of the GitHub repository edaywalid/memalloc, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/edaywalid/memalloc
- Repository: https://github.com/edaywalid/memalloc

## Overview

##### Main Components

a) Memory Management Layer
- Custom Memory Allocator (memalloc.c/h)
- System Call Interface (sbrk)
- Heap Memory Space

b) Data Structure Examples Layer
- Linked List Implementation
- Binary Tree Implementation
- Directed Graph Implementation

**Level 1 (Top): Client Applications**
- ↓
**Level 2: Data Structure Implementations**
- ↓
**Level 3: Memory Management Layer**
- ↓
**Level 4 (Bottom): Operating System Layer**

##### Component Relationships

Use the following connection types:
- Double lines for system call boundaries

##### Specific Elements

a) Operating System Layer (Bottom):
- Sbrk system call interface

b) Memory Management Layer:
- Heap memory space management
- Memory block allocation strategy

c) Data Structure Layer:

d) Client Application Layer:
- Potential application usage

##### Important Details to Capture

- Memory Block Management:
- How memory blocks are organized
- Free and allocated spaces
- Metadata storage

- System Call Interface:
- Boundary between user space and kernel space
- Sbrk interaction

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef os fill:#gray,stroke:#333
    classDef memory fill:#blue,stroke:#333
    classDef datastructure fill:#green,stroke:#333
    classDef client fill:#yellow,stroke:#333
    classDef future fill:#lightgray,stroke:#333,stroke-dasharray: 5 5

    %% Client Layer
    subgraph ClientLayer
        Client["Client Applications"]:::client
    end

    %% Data Structures Layer
    subgraph DataStructures
        LinkedList["Linked List"]:::datastructure
        BinaryTree["Binary Tree"]:::datastructure
        DirectedGraph["Directed Graph"]:::datastructure
    end

    %% Memory Management Layer
    subgraph MemoryManagement
        MemAlloc["Memory Allocator\n(memalloc.c/h)"]:::memory
        HeapSpace["Heap Memory Space"]:::memory
        BlockMgmt["Block Management\nMetadata"]:::memory
    end

    %% Future Implementations
    subgraph FutureFeatures
        ThreadSafety["Thread Safety"]:::future
        Calloc["calloc()"]:::future
        Realloc["realloc()"]:::future
    end

    %% OS Layer
    subgraph OSLayer
        Kernel["Unix Kernel"]:::os
        SysCalls["sbrk System Call"]:::os
    end

    %% Relationships
    Client --> LinkedList
    Client --> BinaryTree
    Client --> DirectedGraph
    
    LinkedList --> MemAlloc
    BinaryTree --> MemAlloc
    DirectedGraph --> MemAlloc
    
    MemAlloc --> BlockMgmt
    MemAlloc --> HeapSpace
    HeapSpace --> SysCalls
    SysCalls --> Kernel

    %% Future Feature Connections
    MemAlloc -.-> ThreadSafety
    MemAlloc -.-> Calloc
    MemAlloc -.-> Realloc

    %% Click Events
    click MemAlloc "https://github.com/edaywalid/memalloc/blob/main/memalloc.c"
    click LinkedList "https://github.com/edaywalid/memalloc/blob/main/examples/linked_list.c"
    click BinaryTree "https://github.com/edaywalid/memalloc/blob/main/examples/binary_tree.c"
    click DirectedGraph "https://github.com/edaywalid/memalloc/blob/main/examples/directed_graph.c"

    %% Legend
    subgraph Legend
        L1["Client Layer"]:::client
        L2["Data Structures"]:::datastructure
        L3["Memory Management"]:::memory
        L4["Operating System"]:::os
        L5["Future Features"]:::future
    end
```
