Add refcounted data

Desktop / GNOME / GLib - Emmanuele Bassi [gnome.org] - 9 July 2018 09:11 EDT

It is useful to provide a "reference counted allocation" API that can add reference counting semantics to any memory allocation. This allows turning data structures that usually are placed on the stack into memory that can be placed on the heap without:

- adding a public reference count field- implementing copy/free semantics

This mechanism is similar to Rust's Rc> combination of traits, and uses a Valgrind-friendly overallocation mechanism to store the reference count into a private data segment, like we do with GObject's private instance data.

c5d2417d0 Add refcounted data
docs/reference/glib/glib-docs.xml | 1 +
docs/reference/glib/glib-sections.txt | 12 +
glib/Makefile.am | 2 +
glib/glib.h | 1 +
glib/grcbox.c | 398 ++++++++++++++++++++++++++++++++++
glib/grcbox.h | 55 +++++
glib/meson.build | 2 +
glib/tests/Makefile.am | 1 +
glib/tests/meson.build | 1 +
glib/tests/rcbox.c | 82 +++++++
10 files changed, 555 insertions(+)

Upstream: git.gnome.org


  • Share