Module tanya.memory.smartref

Smart pointers.

A smart pointer is an object that wraps a raw pointer or a reference (class, dynamic array) to manage its lifetime.

This module provides two kinds of lifetime management strategies:

Functions

NameDescription
refCounted(allocator, args) Constructs a new object of type T and wraps it in a RefCounted using args as the parameter list for the constructor of T.
refCounted(allocator, size) Constructs a new array with size elements and wraps it in a RefCounted.
unique(allocator, args) Constructs a new object of type T and wraps it in a Unique using args as the parameter list for the constructor of T.
unique(allocator, size) Constructs a new array with size elements and wraps it in a Unique.

Structs

NameDescription
RefCounted Reference-counted object containing a T value as payload. RefCounted keeps track of all references of an object, and when the reference count goes down to zero, frees the underlying store.
Unique Unique stores an object that gets destroyed at the end of its scope.