GithubHelp home page GithubHelp logo

arena-allocator's Introduction

Arena Allocator

Arena allocators are region based allocators that tie many allocations to a single region of memory. Benefits are massivly simplified allocation and deallocation for complex structures, increased performance due to improved cache locality, and reduced memory fragmentation as long as individual items don't need to be deallocated. For programs that need to micro-manage individual allocations this is not an ideal solution.

Deallocating a region of memory with arenas is extremely fast, because the arena length is just set to 0. Allocating memory is also extremely fast. This implementation also grows the arena on demand using mmap and mprotect. Extending the library with a new type of allocation strategy should be easy.

Reference

arena_t arena_new()

Allocate a new arena.

If arena_new() fails, the struct member data is set to NULL. This can be checked with arena_new_failed()

bool arena_new_failed(arena_t *a)

Returns true if creating a new arena failed

int arena_delete(arena_t *a)

Delete underlying buffer of arena. Should only be used with arenas from arena_new().

Returns 0 on success, -1 on failure

arena_t arena_attach(void *ptr, size_t size)

Attach an arena to an existing memory region. The arena will not expand if capacity is exceeded.

void *arena_detatch(arena_t arena)

Detach an arena from an existing memory region. Returns the underlying data.

void arena_reset(arena_t *a)

Resets an arena.

void *arena_alloc(arena_t *a, size_t len)

Allocate memory with an arena. Returns NULL and sets errno on failure.

void *arena_calloc(arena_t *a, size_t nmemb, size_t size)

Allocate and zero memory with an arena. Returns NULL and sets errno on failure.

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.