jgabaut / koliseo

An arena allocator library in C.
https://jgabaut.github.io/koliseo-docs
GNU General Public License v3.0
5 stars 0 forks source link
allocator amboso arena-allocator c c11

koliseo

A C library for a simple arena allocator.

Table of Contents

What is this thing?

This is a C library for an arena allocator, whose arenas are named Koliseo. It offers a basic API to perform initialisation, push (request arena memory), reset and free of a Koliseo.

If you compile it without defining any special macros, you will get the basic functionality.

Basic example

This is a basic usage example, initialising a Koliseo and then pushing an example pointer. You can build it by running:

gcc static/basic_example.c src/koliseo.c -o basic_example

For a more complete example, including Koliseo_Temp usage, check out demo.c provided in static folder.

typedef struct Example {
    int val;
} Example;

#include "../src/koliseo.h"

int main(void)
{
    //Init the arena
    Koliseo* kls = kls_new(KLS_DEFAULT_SIZE);

    //Use the arena (see demo for Koliseo_Temp usage)
    Example* e = KLS_PUSH(kls, Example);
    e->val = 42;

    //Show contents to stdout
    print_dbg_kls(kls);

    //Free the arena
    kls_free(kls);
    return 0;
}

After including the koliseo.h header:

Extra features

By default, extended functionalities are not included in the build, with each feature needing a preprocessor macro to be defined before including the library header. You can find hints on configuration here, or the list of macros here.

Region

A ready-to-go index for every allocation you make.

Core debug

Extra debug for core calls, may be too verbose for some applications.

Gulp

Utility to memory-map a file (always the best idea, right?) to a C string, by providing the filepath.

List template

Any time LIST_T is defined before including templates/list.h, a basic linked-list implementation supporting Koliseo allocation will be declared for the passed type.

Experimental

Include some experimental (NOT WELL TESTED. USE WITH CAUTION) functions.

In particular, enables the dreaded pop operation and its functions.

How to enable extra features

To aid in building with extra features, see this section.

The preprocessor macros to enable them manually are:

Documentation

HTML docs are available at this Github Pages link.

You can also get the ready pdf version of the docs from the latest release.

If you have doxygen you can generate the HTML yourself, or even the pdf if you have doxygen-latex or equivalents.

Prerequisites

To build the demo binary, you need:

Configuration

To prepare the files needed by autotools, run:

  aclocal
  autoconf
  automake --add-missing
  ./configure # Optionally, with --enable-debug or --host
  make

You will get a ./configure script, which you can use to enable debug mode or other features.

Building

To build both the libkoliseo.so lib and demo binary, run:

Supported platforms

ATM the code should build for:

Credits

Thanks to skeeto for showing me the original base implementation.

Thanks to Mako for the repo banner.

Thanks to Tsoding for its creative string view library (repo), which indeed does things so simply you mostly can't do anything different.

Thanks to David Priver for its dynamic array template example.

Todo