Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


CheckGetSecondaryDataPointerAndThrow(AtomicSafetyHandle)

Check whether it's safe to create a memory-aliasing view to a native container.
Read time 1 minuteLast updated 19 days ago

Definition

[Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]public static void CheckGetSecondaryDataPointerAndThrow(AtomicSafetyHandle handle)

Parameters

The AtomicSafetyHandle to check.

Remarks

Use this method when you implement native container methods that create memory-aliasing views, such as
GetEnumerator
or
AsArray
. This method checks whether it is safe to copy the data pointer to the backing memory of the native container into a new view structure that uses the secondary version number.
This method checks if there are pending jobs that might affect the size of the native container and risk reallocating the container's backing memory. This method doesn't throw an exception if the job writes through an
AtomicSafetyHandle
that uses a secondary version number.
The difference between this method and
<see cref="Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckReadAndThrow"></see>
is that that
CheckReadAndThrow
throws an exception if there are any pending jobs writing to the native container.
CheckGetSecondaryDataPointerAndThrow
throws an exception only if there is a risk of a job reallocating the native container's backing memory, which makes the data pointer copied to the view invalid.
For more information about secondary version numbers and safe access to dynamic containers, refer to Copying NativeContainer structures.
Additional Resources: NativeContainerAttribute.