arena allocator + incremental garbage collector
  • C++ 98.4%
  • CMake 1.6%
Find a file
2023-09-27 18:23:40 -04:00
.github/workflows build: adopt xo-cmake dependency 2023-09-27 09:29:47 -04:00
cmake refcnt: build tidy 2023-09-27 17:34:19 -04:00
include refcnt: build + install fixes 2023-09-24 12:27:19 -04:00
src refcnt: build: streamline, using xo-cmake macros 2023-09-27 17:07:49 -04:00
utest refcnt: build: streamline, using xo-cmake macros 2023-09-27 17:07:49 -04:00
CMakeLists.txt randomgen: consolidate CMAKE_EXPORT_COMPILE_COMMANDS 2023-09-27 18:23:40 -04:00
README.md build: adopt xo-cmake dependency 2023-09-27 09:29:47 -04:00

intrusive reference counting

Refcnt is a small shared library supplying intrusive reference counting.

Features

  • base class ref::Refcounted. Application classes opt-in to reference counting by inheriting this class.
  • common base simplifies connecting to common-base-object applications such as python, java etc.

Getting Started

build + install indentlog dependency

see github/Rconybea/indentlog

copy refcnt repository locally

$ git clone git@github.com:rconybea/refcnt.git
$ ls -d refcnt
refcnt

build + install

$ cd refcnt
$ mkdir build
$ cd build
$ cmake -DCMAKE_MODULE_PATH=${INSTALL_PREFIX}/share/cmake  -DCMAKE_PREFIX_PATH=${INSTALL_PREFIX} -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} ..
$ make
$ make install

CMAKE_PREFIX_PATH should point to prefix where indentlog is installed

alternatively, if you're a nix user:

$ git clone git@github.com:rconybea/xo-nix.git
$ ls -d xo-nix
xo-nix
$ cd xo-nix
$ nix-build -A refcnt

build for unit test coverage

$ cd refcnt
$ mkdir ccov
$ cd ccov
$ cmake -DCMAKE_MODULE_PATH=${INSTALL_PREFIX}/share/cmake  -DCMAKE_PREFIX_PATH=${INSTALL_PREFIX} -DCODE_COVERAGE=ON -DCMAKE_BUILD_TYPE=Debug ..

Examples

1

#include "refcnt/Refcounted.hpp"

using xo::ref::Refcounted;

struct MyObject : public Refcounted {
     static rp<MyObject> make() { return new MyObject(); }

private:
     // intrusively-reference-counted objects should only be heap-allocated
     MyObject() { ... }
};

int main() {
     // create reference-counted instance
     auto x = MyObject::make();
     auto y = x;
     // x,y refer to the same instance.
     x = nullptr;
     // y holds last reference
     y = nullptr;
     // MyObject has been deleted
}

2

To log reference-counting activity

xo::ref::intrusive_ptr_set_debug(true);