Giter Club home page Giter Club logo

arena's Introduction

Arena allocator

My personal approach to arena allocation. Read more about the design and motivation of this allocator here: https://ziap.github.io/blog/arena

How to use

The code is implemented in C as an STB-style single-header library. The header is portable and can be used on its own. But platform-specific source files are also available to "configure" the library to use the system page allocator. This separation breaks the rule of header-only libraries, but it allows for easier addition of target platforms.

Using the library as a single-header header library is the same as any other library of the same type: select exactly one C source file that instantiates the code by defining ARENA_IMPLEMENTATION.

#define ARENA_IMPLEMENTATION
#include "arena.h"

The platform-specific source files act as the instantiation source files. So if you use one of those, don't define ARENA_IMPLEMENTATION anywhere else.

Adding a new platform

To add a new platform, redefine these two macros to call your platform's allocator.

#define ARENA_BACKEND_ALLOC(size) ...
#define ARENA_BACKEND_DEALLOC(ptr, size) ...

#define ARENA_IMPLEMENTATION
#include "arena.h"

You can also define ARENA_BACKEND_RESIZE if your platform supports efficient reallocation, but it is not required, as the library can automatically implement that with ARENA_BACKEND_ALLOC and ARENA_BACKEND_DEALLOC.

Configuration

Some macros that you can redefine to configure the library:

Macro Usage
ARENA_MEMCPY Redefine if your platform can't use libc's memcpy
ARENA_ALIGNMENT Customize the memory alignment. Default is sizeof(void*)
ARENA_MAX_SIZE The maximum size of each chunk, should be page-aligned

License

This project is licensed under the MIT License.

arena's People

Contributors

ziap avatar

Stargazers

Quang-Truong Nguyen avatar

Watchers

 avatar

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.