Constructor that initializes the payload.
Destructor that tracks the reference count appropriately. If !refCountedStore.isInitialized, does nothing. When the reference count goes down to zero, calls destroy agaist the payload and calls free to deallocate the corresponding resource.
Constructor that tracks the reference count appropriately. If !refCountedStore.isInitialized, does nothing.
Returns a reference to the payload. If (autoInit == RefCountedAutoInitialize.yes), calls refCountedStore.ensureInitialized. Otherwise, just issues assert(refCountedStore.isInitialized).
Assignment operators
Returns a reference to the payload. If (autoInit == RefCountedAutoInitialize.yes), calls refCountedStore.ensureInitialized. Otherwise, just issues assert(refCountedStore.isInitialized). Used with alias refCountedPayload this;, so callers can just use the RefCountedNoGC object as a T.
Returns storage implementation struct.
RefCountedNoGC storage implementation.
// A pair of an $(D int) and a $(D size_t) - the latter being the // reference count - will be dynamically allocated auto rc1 = RefCountedNoGC!int(5); assert(rc1 == 5); // No more allocation, add just one extra reference count auto rc2 = rc1; // Reference semantics rc2 = 42; assert(rc1 == 42); // the pair will be freed when rc1 and rc2 go out of scope
Defines a reference-counted object containing a T value as payload. RefCountedNoGC keeps track of all references of an object, and when the reference count goes down to zero, frees the underlying store. RefCountedNoGC uses malloc and free for operation.
RefCountedNoGC is unsafe and should be used with care. No references to the payload should be escaped outside the RefCountedNoGC object.
The autoInit option makes the object ensure the store is automatically initialized. Leaving autoInit == RefCountedAutoInitialize.yes (the default option) is convenient but has the cost of a test whenever the payload is accessed. If autoInit == RefCountedAutoInitialize.no, user code must call either refCountedStore.isInitialized or refCountedStore.ensureInitialized before attempting to access the payload. Not doing so results in null pointer dereference.