Git Product home page Git Product logo

rpmalloc-zig-port's Introduction

rpmalloc zig port

This project is an attempt to make a fast general-purpose allocator for zig. It is mostly derived from rpmalloc, using the same general structure and mostly retaining the essential strategies that make it fast, though with many options and facets stripped down or modified to suit Zig.

WIP

This project is under development, does not guarantee a stable API and lacks documentation and tests. Contributions, in the form of PRs and relevant resources, are greatly appreciated.

Usage

It's quite trivial to use, just add some code along the lines of

exe.addPackagePath("rpmalloc", "path/to/rpmalloc/src/rpmalloc.zig");

to your build.zig, and then import it and use like so:

const rpmalloc = @import("rpmalloc");
const Rp = rpmalloc.RPMalloc(.{});

pub fn main() !void {
    try Rp.init(null, .{});
    defer Rp.deinit();

    const allocator = Rp.allocator();
    // -- snip --
}

Although it should be clear from the example, I'll note that this allocator is indeed a singleton, much like in the original C source, with an important distinction being that you can concurrently have different permutations based on the configuration.

Notes

  • There are a good few TODO comments in the code, comprised mostly of uncertanties on as to the benefits or semantics of certain parts of the code.
  • At the time of writing, the port runs marginally slower than the original C source in the benchmark when linked statically, and notably slower when linked dynamically.
  • I've opted to remove most code related to partial unmapping, as it's not a pattern that is well-suited to Zig (or at least that I couldn't figure out how to map to Zig's prototypical allocator patterns).

rpmalloc-zig-port's People

Contributors

inkryption avatar rganesan avatar

Stargazers

 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.