Skip to content
CShift0.32

SharedPtr<T>

Struct · built-in type

struct SharedPtr<T>

A value in a reference-counted box that threads can share: SharedPtr<T>.Create(value) moves the value into the box, copies of the SharedPtr share it, and the last one frees it. The reference count is atomic, so copies can go to other threads; the value must then be thread-safe itself (no strings, arrays or containers inside).

The value is not locked: concurrent changes through SharedPtr<T>.Ptr need their own synchronization, or a Mutex.

Name Description
Create A new box with value.
static SharedPtr<T> Create(T value)

A new box with value.

Name Description
IsNull Whether there is no box (a null or default SharedPtr).
Get A copy of the value in the box.
Ptr A pointer to the value in the box, for changing it in place (unsafe).
bool IsNull()

Whether there is no box (a null or default SharedPtr).

T Get()

A copy of the value in the box.

T* Ptr()

A pointer to the value in the box, for changing it in place (unsafe).