Navigation
API > API/Plugins > API/Plugins/UAFAnimNode
A reference to a value type that performs Copy-on-Write. A reference is never invalid, it must always be constructed from valid data.
A CoW Reference tracks 3 things:
- A pointer to an allocated value
- Whether or not it owns the allocated memory (if we own it, the reference is unique)
- Whether or not the reference is immutable
For performance reasons, this tracking is performed using a single pointer where the bottom two bits are used to store our metadata. We thus require an alignment of 4 bytes for all allocations.
Mutability is enforced at runtime not through the type system (e.g. with 'const'). The specified allocator will be used when a copy is made and memory is owned by the reference.
Copying or assigning a reference to another always performs a copy where the new reference owns the resulting memory. This occurs regardless whether or not the source/target are mutable/immutable.
It is always safe to query for a const reference using TUAFCoWRef::Get() regardless of whether or not the underlying reference is immutable. However, care must be taken when using TUAFCoWRef::GetMutable(). It is the responsibility of the caller to ensure that the reference is mutable before attempting to use it as such. If the reference is not mutable, TUAFCoWRef::ForceMutable() can be used to convert it.
Two allocators are supported: FDefaultAllocator and TMemStackAllocator.
| Name | TUAFCoWRef |
| Type | class |
| Header File | /Engine/Plugins/Experimental/UAF/UAFAnimNode/Source/UAFAnimNode/Public/UAF/UAFCoWRef.h |
| Include Path | #include "UAF/UAFCoWRef.h" |
Syntax
template<class ValueType, class AllocatorType>
class TUAFCoWRef
Constructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
TUAFCoWRef
(
const TUAFCoWRef< ValueType, OtherAllocatorType >& Other |
Constructs a new mutable reference by performing a copy of the input reference. | UAF/UAFCoWRef.h | |
TUAFCoWRef () |
Disable construction of empty references. | UAF/UAFCoWRef.h | |
TUAFCoWRef
(
const TUAFCoWRef< ValueType, AllocatorType >& Other |
Constructs a new mutable reference by performing a copy of the input reference. | UAF/UAFCoWRef.h | |
TUAFCoWRef
(
TUAFCoWRef< ValueType, AllocatorType >&& Other |
Move a reference into another. | UAF/UAFCoWRef.h |
Destructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
~TUAFCoWRef() |
Destroys the current reference If it owned the memory within, it is freed | UAF/UAFCoWRef.h |
Constants
| Name | Type | Remarks | Include Path |
|---|---|---|---|
| FLAGS_MASK | uintptr_t | UAF/UAFCoWRef.h | |
| IS_MUTABLE_FLAG_BIT | uintptr_t | UAF/UAFCoWRef.h | |
| OWNS_MEMORY_FLAG_BIT | uintptr_t | UAF/UAFCoWRef.h | |
| VALUE_PTR_MASK | uintptr_t | UAF/UAFCoWRef.h |
Variables
Protected
| Name | Type | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|---|
| ValuePtrAndFlags | uintptr_t | Stores a pointer to a value and 2 flags in the LSBs. | UAF/UAFCoWRef.h |
Functions
Public
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
void ForceMutable() |
Ensures that this reference is mutable If the current reference was immutable and we do not own the memory, this performs a copy (Copy-on-Write) Note that any existing const references will remain valid since the original owner is keeping it alive | UAF/UAFCoWRef.h | |
const ValueType & Get() |
Returns an immutable reference to the value contained within. | UAF/UAFCoWRef.h | |
ValueType & GetMutable() |
Returns a mutable reference to the value contained within. | UAF/UAFCoWRef.h | |
bool IsMutable() |
Returns whether or not this reference is mutable. | UAF/UAFCoWRef.h | |
bool IsUnique() |
Returns whether or not this reference is unique A reference is unique if we own its memory | UAF/UAFCoWRef.h |
Static
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
static TUAFCoWRef< ValueType, AllocatorType > MakeFrom
(
ValueType&& Value |
Constructs a new mutable reference from the specified value by performing a move of the input. | UAF/UAFCoWRef.h | |
static TUAFCoWRef< ValueType, AllocatorType > MakeImmutable
(
const ValueType* ValuePtr |
Constructs a new immutable reference from the specified value pointer. | UAF/UAFCoWRef.h | |
static TUAFCoWRef< ValueType, AllocatorType > MakeMutable
(
ValueType* ValuePtr |
Constructs a new mutable reference from the specified value pointer. | UAF/UAFCoWRef.h |
Operators
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
TUAFCoWRef< ValueType, AllocatorType > & operator=
(
const TUAFCoWRef< ValueType, AllocatorType >& Other |
Assign a new mutable reference by performing a copy of the input reference. | UAF/UAFCoWRef.h | |
TUAFCoWRef< ValueType, AllocatorType > & operator=
(
const TUAFCoWRef< ValueType, OtherAllocatorType >& Other |
Assign a new mutable reference by performing a copy of the input reference. | UAF/UAFCoWRef.h | |
TUAFCoWRef< ValueType, AllocatorType > & operator=
(
TUAFCoWRef< ValueType, AllocatorType >&& Other |
Move assign a reference into another. | UAF/UAFCoWRef.h | |
TUAFCoWRef< ValueType, AllocatorType > & operator=
(
ValueType&& Value |
Move assign a value into a reference by performing a move of the input. | UAF/UAFCoWRef.h |