Coder Social home page Coder Social logo

alitokur / arena-allocator Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 29 KB

The Arena Allocator (Linear Allocator) is a custom memory allocater written in C++. It provides a high-performance memory management solution for applications that require efficient and predictable memory allocation and deallocation.

License: MIT License

CMake 4.66% C++ 95.34%
arena-allocator cpp linear-allocator memory memory-allocation memory-management

arena-allocator's Introduction

Arena Allocator

A custom memory allocator written in C++.

Work In Progress Build

Table of Contents

Arena Allocator

The Arena Memory Allocator (region based memory allocator) is a fundamental custom memory allocation system. It involves creating a single large memory block and using an offset to manage allocations. The offset serves as a reference point for the last allocated memory location.

Pros

Speed: Arena allocators can be faster than dynamic allocations because there's no need to manage a list of free blocks or perform complex searches for suitable memory blocks.

Predictable: Memory fragmentation is less of an issue with arena allocators, as you're allocating memory in large, contiguous chunks.

Memory Leak Prevention: When the arena goes out of scope or is explicitly deallocated, all the memory allocated within it is automatically freed, reducing the risk of memory leaks.

Cons

Arenas can be less flexible than other memory allocation techniques because you have to determine the maximum memory requirement upfront. They may not be suitable for applications with highly variable or unpredictable memory needs.

Memory Alignment

Memory alignment is indeed an important concept in computer architecture and memory management. It's essential for optimizing memory access and ensuring that data is accessed in a way that aligns with the word size of the computer architecture.

Modern computer architectures typically have a specific word size, which is the amount of data the processor can read from memory in a single operation. For example, on 32-bit systems, the word size is typically 4 bytes, and on 64-bit systems, it is often 8 bytes. Memory alignment ensures that data structures start at addresses that are multiples of the word size.

FAQ

  • Why I use malloc in the custom memory allocator? Is it already an allocator?
  • Can i use brk() or sbrk() instead of malloc();

Build

You can build Arena Allocator by following these steps:

  • Clone the repository:
git clone 
  • Create a build directory:
mkdir build && cd build
  • Run CMake:
cmake ..
  • Build the project:
make

If the build is successful, you should see the executable file for your project in the build directory. If you encounter any issues during the build process or have questions, please don't hesitate to reach out for assistance. Please note that the Arena Allocator is currently compatible with Linux systems. Support for other operating systems may be added in the future as the project evolves. Arena Memory Allocator is indeed simple and often do not support fine-grained memory deallocation where you can free individual memory blocks. In arena allocator, memory is typically released all at once, which means that when you are done with the entire arena, you deallocate the entire areana in a single operation.

Contributing

If you would like to contribute, please follow these guidelines:

  • Fork the repository and make changes on your own fork.
  • Ensure that your code adheres to the existing code formatting and style guidelines.
  • Write clear commit messages and pull request descriptions.

Contact

If you have any questions, feedback or suggestions, please feel free to contact me at [email protected] . You can also follow me on Twitter at @alitokur. I'm always open to feedback and would love to hear from you!

arena-allocator's People

Contributors

alitokur avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

arena-allocator's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.