Skip to content
swarnendiPublic

About

A custom built C++ memory allocator focused on simplicity and user control

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

Repository files navigation

alloc

A lightweight C++ memory pool allocator.

alloc is a simple, byte-oriented bump allocator that manages a preallocated block of contiguous memory.

Features

  • Contiguous memory pool
  • Bump allocation strategy
  • Allocation bounds checking
  • Memory pool reset and reuse
  • Automatic memory cleanup
  • Lightweight C++ implementation

Project Structure

alloc/
├── include/
│   └── alloc/
│       └── allocator.hpp
├── src/
│   └── allocator.cpp
├── examples/
│   └── basic.cpp
├── tests/
│   └── allocator_test.cpp
├── CMakeLists.txt
└── README.md

Requirements

  • C++17 compatible compiler
  • CMake 3.20 or newer

Building

git clone YOUR_REPOSITORY_URL
cd alloc

cmake -S . -B build
cmake --build build

Usage

#include <iostream>
#include "alloc/allocator.hpp"

int main()
{
    mem_pool pool(1024);

    void* memory = pool.allocate(64);

    if (memory == nullptr)
    {
        std::cout << "Allocation failed\n";
        return 1;
    }

    std::cout << "Allocation successful\n";

    pool.reset();

    std::cout << "Memory pool reset\n";
}

API Reference

Method Description
mem_pool(size_t) Constructs a memory pool with the specified capacity
allocate(size_t) Allocates memory from the pool
reset() Resets pool usage to zero, allowing memory to be reused

How It Works

alloc uses a bump allocation strategy.

A fixed block of contiguous memory is allocated when a mem_pool object is constructed. Subsequent allocation requests receive portions of that block.

The allocator tracks used capacity and rejects requests that exceed the remaining space.

The reset() method resets the allocation counter to zero, allowing the entire pool to be reused without allocating another block of memory.

Memory is released automatically when the pool is destroyed.

Limitations

  • No individual deallocation.
  • No automatic memory resizing.
  • No general-purpose alignment guarantee for arbitrary allocation offsets.
  • The allocator is not thread-safe.

License

This project is licensed under the MIT License.

See LICENSE for details.

About

A custom built C++ memory allocator focused on simplicity and user control

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages