Navigation
API > API/Runtime > API/Runtime/GeometryCore > API/Runtime/GeometryCore/DynamicMesh
References
| Module | GeometryCore |
| Header | /Engine/Source/Runtime/GeometryCore/Public/DynamicMesh/MeshSharingUtil.h |
| Include | #include "DynamicMesh/MeshSharingUtil.h" |
Syntax
template<typename ObjectType>
class TConstObjectSharedAccess
Remarks
TConstObjectSharedAccess provides a way for the owner of some object (eg a Mesh) to share read-only access to that object with background threads.
This avoids the obvious alternative, using TSharedPtr, which tends to result in some bad patterns (in particular calling code that /doesn't/ have a shared pointer to the object, now has to make a copy, or also convert all related code to use a shared pointer).
Currently TConstObjectSharedAccess's template ObjectType must be default constructible. This allows the background threads to still access an instance of ObjectType even if the owner thread/code decides to revoke access. In that case, TConstObjectSharedAccess provides an "empty" ObjectType instead. (the background processing code must handle this case).
TConstObjectSharedAccess can be constructed with either a raw pointer to ObjectType, or a TSharedPtr. In the raw pointer case, the creator is responsible for destruction.
The standard usage pattern is:
[Owner thread] T* ObjectPtr = (...); TSharedPtr
[Background thread] SharedAccess->AccessSharedObject( const ObjectType& Object { do_my_stuff(Object); } );
[Owner thread (later)] SharedAccess->ReleaseSharedObject();
Note that a TSharedPtr does not strictly need to be used. However this allows the Owner thread to destruct the Object, and/or terminate, and the background thread can still safely access a shared ObjectType (now empty).
Variables
| Type | Name | Description | |
|---|---|---|---|
| ObjectType | EmptyObject | Default-constructed value of ObjectType that will be returned if ObjectRawPtr and ObjectSharedPtr are both null/invalid | |
| FCriticalSection | ObjectLock | Controls access to the shared object | |
| const ObjectType * | ObjectRawPtr | Only one of ObjectRawPtr or ObjectSharedPtr should be initialized. ObjectRawPtr will be checked first. | |
| TSharedPtr< ObjectType > | ObjectSharedPtr |
Constructors
| Type | Name | Description | |
|---|---|---|---|
TConstObjectSharedAccess
(
const ObjectType* Object |
Construct shared access to a raw pointer of ObjectType | ||
TConstObjectSharedAccess
(
TSharedPtr< ObjectType > Object |
Construct shared access to a shared pointer of ObjectType |
Destructors
| Type | Name | Description | |
|---|---|---|---|
Functions
| Type | Name | Description | |
|---|---|---|---|
| bool | AccessSharedObject
(
TFunctionRef< void(const ObjectType&)> ProcessFunc |
Call ProcessFunc(Object) on the shared Object. | |
| void | Release the shared object. |