Skip to content

felixnagele/malloc-from-scratch

malloc-from-scratch 🧩

A custom memory allocator implementation in C++. This project implements malloc, free, calloc, and realloc from scratch using only native C++ (no external dependencies). This is done by using the system call sbrk() to manage memory at a low level.

CI

✨ Features

  • Implements malloc, free, calloc, and realloc from scratch
  • Uses native C++ only (no external dependencies)
  • Custom memory management strategies
  • Test suite with different test types and memory leak detection

🛠 Requirements

  • CMake 3.14 or higher
  • C++17 compatible compiler
  • No external libraries required - 100% native C++

🚀 Quick Start - Linux (Ubuntu/Debian)

Step 1: Clone the repo

git clone https://github.com/felixnagele/malloc-from-scratch.git
cd malloc-from-scratch

Step 2: Update and install build tools and dependencies

sudo apt update && sudo sudo apt install -y build-essential cmake clang-format clang-tidy strace

Step 3: Configure build directory

cmake -S . -B build

Step 4: Build the project

cmake --build build

One-liner setup

git clone https://github.com/felixnagele/malloc-from-scratch.git && cd malloc-from-scratch && sudo apt update && sudo apt install -y build-essential cmake clang-format clang-tidy strace && cmake -S . -B build && cmake --build build

📖 Usage - Linux (Ubuntu/Debian)

Verify installation

gcc --version
cmake --version
clang-format --version
clang-tidy --version
strace --version

Formatting

Check formatting (what CI does)

find src include tests -name "*.cpp" -o -name "*.h" | xargs clang-format --dry-run -Werror

Auto-fix formatting

find src include tests -name "*.cpp" -o -name "*.h" | xargs clang-format -i

Linting

Run clang-tidy static analysis (what CI does)

find src tests -name "*.cpp" -exec clang-tidy -p build {} \;

🧪 Running Tests

Run tests locally:

cmake --build build && ctest --test-dir build

For detailed test usage with instructions, see tests/README.md.

Tests also run automatically in CI/pipeline here.

Contributing, License & Support

See Community Profile for guidelines, license, and support.

About

A userspace libc heap allocator implementing malloc, calloc, realloc and free in C++ using sbrk

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published