Simple conservative GC using mimalloc

Overview

migc

Small and simple library that implements conservative GC using mimalloc API.

Features

  • Small and tiny. libmigc.so is just 20KB when linked with mimalloc.
  • Has API that is needed by most users of conservative GCs in C and can replace BDWGC in simple cases (e.g when precise marking is not needed) There is: migc_add_roots and migc_delete_roots to add or delete range of pointers to scan for potential pointers, migc_register_finalizer to invoke finalizers on dead objects.
  • Fast allocation. When there is multiple instances of migc heap running in multiple threads this library could get much much faster than BDWGC, in single threaded situations it should be pretty fast too since mimalloc is fast in single threaded apps too.
  • Small overhead per allocation: 8 bytes. These 8 bytes is used to store mark,live bit and finalizer pointer (if exists).

Limitations

  • No threading support. migc_heap type can be used only in thread it was created in.
  • No API for precise marking, I could add such API in the future but I think it will increase allocation overhead by another 8 bytes.
  • Only Mark&Sweep is provided at the moment. There is no advanced GC techniques such as incremental or concurrent marking but sticky generational mark&sweep algorithm could be implemented in the future.

Building

git clone https://github.com/playxe/migc
cd migc
make submodules
make

This should produce libmigc.so which can be dynamically linked with your programs.

Examples

#include "migc.h"
// NOTE: current_stack_pointer is provided by migc.h

int main() {
  migc_heap heap;
  migc_heap_init(&heap,current_stack_pointer() /*stack start for conservative scanning */,1024/* GC threshold */);
  int* mptr = migc_malloc(&heap,sizeof(int)*4);
  keep_on_stack(mptr); // <- optional call, this forces compiler to put variable on stack rather than registers so GC can definitely see it
  mptr[0] = 42;
  printf("%i\n",mptr);
  migc_collect(&heap);
}

You might also like...
A simple web browser written for learning purposes in C++
A simple web browser written for learning purposes in C++

AWB: Abbix's web browser pls send help AWB is a simple web browser written for learning purposes in C++, it features a custom engine named orca render

A simple tcp/ip stack

pip A simple TCP/IP stack, just like lwIP, but pip focus only parse IP Packet and output IP Packet, basically realize no memory copy 一个简单的TCP/IP协议栈实现,

HevSocks5Core is a simple, lightweight socks5 library

A simple, lightweight socks5 library. (IPv4/IPv6/TCP/UDP/Client/Server)

A simple and easy WiFi-enabled ESP8266-powered WSPR and FT8 beacon which uses NTP + DS3231 RTC for timing.
A simple and easy WiFi-enabled ESP8266-powered WSPR and FT8 beacon which uses NTP + DS3231 RTC for timing.

Easy-Digital-Beacons-v1 A simple and easy WiFi-enabled ESP8266-powered WSPR and FT8 beacon which uses NTP + DS3231 RTC for timing. The whole design is

kleinsHTTP: A stupid stupidly simple http server.

kleinsHTTP: A stupid stupidly simple http server. About I wanted to create an api server using C++ as it is my favorite language however i was unable

Simple WHIP Client (based on GStreamer's webrtcbin)

Simple WHIP Client This is an attempt to create a simple prototype of a WHIP client, to be used mostly for testing with my Simple WHIP Server (based o

Simple HTTP protocol implementation in C

C-SimpleHTTP A simple HTTP protocol implementation in C How do i run it? First of all, this project is made in c, then you will need GCC Compiler. The

A Simple CLI Network Packet Sniffer
A Simple CLI Network Packet Sniffer

packt packt is a simple CL(command line) network packet sniffer which can run on any unix-like OS including termux (Android). packt works by first ope

Comments
  • Question about `current_stack_pointer`

    Question about `current_stack_pointer`

    Hey there! First of all: thanks for putting migc on GitHub! I've been looking into writing a conservative GC and it's super helpful to look at migc and see how you do stack scanning.

    I wanted to send you an email but then figured: why not open an issue? So, this is a question and not a bug.

    How is current_stack_pointer supposed to work?

    https://github.com/playXE/migc/blob/fb3b807a2698a1066b3fffd6d2effce5b9c64ab7/migc.h#L303-L309

    There's two things I don't understand:

    1. If I understand it correctly it tries to take the address of an undeclared local variable (sp). Shouldn't this be something like
      int dummy
      return &dummy
      
    2. When I try to compile the example.c with
      $ gcc -O3  migc.c migc.h example.c -o example -L -Wl,-rpath= -L/home/mrnugget/code/clones/migc/mimalloc/out/release -Wl,-rpath=/home/mrnugget/code/clones/migc/mimalloc/out/release -pthread -lmimalloc
      

      I get a bunch of warnings but also this error:

      /usr/bin/ld: /tmp/ccjNSGu8.o: in function `current_stack_pointer':
      example.c:(.text+0x80): multiple definition of `current_stack_pointer'; /tmp/ccoWCpKL.o:migc.c:(.text+0x240): first defined here
      collect2: error: ld returned 1 exit status
      make: *** [Makefile:15: example] Error 1
      

    It seems to me like current_stack_pointer should be inlined, right?

    opened by mrnugget 4
Owner
playX
Real name: Adel Prokurov. Rust programmer. Love doing compiler and VM related development. :) Languages: Russian, English.
playX
Simple server and client using python socket and declarative programming

Socket-programming Simple server and client using python socket and declarative programming How to use? open cmd and navigate to the location of the s

MAINAK CHAUDHURI 24 Dec 17, 2022
Ole Christian Eidheim 741 Dec 27, 2022
A simple SIP server (proxy) for handling VoIP calls based on SIP using C++

Sip Server A simple sip server for handling VoIP calls based on sip protocol. Features Registration Of Users The server supports registration process.

null 8 Nov 3, 2022
A very simple, fast, multithreaded, platform independent HTTP and HTTPS server and client library implemented using C++11 and Boost.Asio.

A very simple, fast, multithreaded, platform independent HTTP and HTTPS server and client library implemented using C++11 and Boost.Asio. Created to be an easy way to make REST resources available from C++ applications.

Ole Christian Eidheim 2.4k Dec 23, 2022
C library to create simple HTTP servers and Web Applications.

Onion http server library Travis status Coverity status Onion is a C library to create simple HTTP servers and Web Applications. master the developmen

David Moreno Montero 1.9k Dec 20, 2022
Simple, small, C++ embeddable webserver with WebSockets support

Seasocks - A tiny embeddable C++ HTTP and WebSocket server for Linux Features Simple C++ API Serves static content from disk API for building WebSocke

Matt Godbolt 624 Jan 3, 2023
Simple, secure & standards compliant web server for the most demanding of applications

Simple, secure[1] & standards compliant[2] web server for the most demanding[3] of applications. Read more... ?? Optimized security Being meticulously

uNetworking AB 15k Dec 30, 2022
A simple emulator for the CHIP-8 interpreted programming language.

CHIP-8 Emulator A simple emulator for the CHIP-8 interpreted programming language written in C (SDL for graphics). About This is a really basic emulat

Leonardo Folgoni 36 Dec 14, 2022
Simple useful interoperability tests for WebRTC libraries. If you are a WebRTC library developer we'd love to include you!

Overview This project aims to be a convenient location for WebRTC library developers to perform interoperability tests. Who can Participate The projec

Aaron Clauson 106 Dec 18, 2022
Android-Login-Offline Simple login form in Java by Mahmoud Gaming

Android-Login-Offline Simple login form in Java by Mahmoud Gaming. I wanted to upload this project long time ago. This project is for experienced modd

Mahmoud Gaming 7 Mar 29, 2022