Git Product home page Git Product logo

wasm-malloc's Introduction

wasm-malloc

A simple implementation of malloc/free for WebAssembly. The heap is a doubly linked lists, with blocks being merged or split if necessary/possible.

At the moment, realloc is not supported. malloc/calloc do not correctly align the memory.

Because the WebAssembly MVP does not support shrinking the linear memory, freed memory can not be released.

Building

This requires the LLVM toolchain (compiled to include the experimental wasm32 target, see yurydelendik/wasmception). The path to the llvm binary directory has to be passed to the compilation script with the LLVM_ROOT environment variable.

Example invocation of the compilation script:

mkdir build
LLVM_ROOT=$HOME/ CFLAGS=-O2 ./compile build/main.wasm src/malloc.c src/test.c

Debug logging can be enabled with the preprocessor macro MALLOC_DEBUG. This also adds the function print_heap() which prints the current layout of the heap to the browser console.

Usage

In C these functions can be included with malloc.h, they have the exact same signature as in the C standard library.

The file test.c exports some test functions that you can call from JavaScript as instance.exports.test_malloc/free/...(...).

wasm-malloc's People

Contributors

maxkl avatar mechmind avatar

Watchers

ByteBard avatar  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.