ChillMagic / TinyGC

Lightweight GC in C++
Apache License 2.0
4 stars 2 forks source link

TinyGC

A light-weighted GC in C++ (C++11) based on mark-and-sweep algorithm.

Features

Use

  1. Create TinyGC::GC object.
  2. Call newValue method to create collectable object.
  3. Call newObject method to create collectable object whose type is a subclass of GCObject.
  4. Call collect to collect garbage.

Examples

Java:

class Point
{
    Point(int x, int y) {
        this.x = x;
        this.y = y;
    }
    int x, y;
}

Point p = new Point(5, 6);

C++ with TinyGC:

class Point : public TinyGC::GCObject
{
    using Int = TinyGC::GCValue<int>*;
public:
    Point(Int x, Int y)
        : x(x), y(y) {}

    Int x, y;

private:
    void GCMarkAllSub() override {
        GCMarkSub(x);
        GCMarkSub(y);
    }
}

int main()
{
    TinyGC::GC GC;
    {
        auto p = GC.newObject<Point>(
            GC.newValue<int>(5),
            GC.newValue<int>(6)
        );
    }
    GC.collect();
}

Note

License

Apache License 2.0