Version: 2022.3
LanguageEnglish
  • C#

UnsafeUtility

class in Unity.Collections.LowLevel.Unsafe

/

Implemented in:UnityEngine.CoreModule

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

Unsafe utility class.

Static Methods

AddressOfThe memory address of the struct.
AlignOfMinimum alignment of a struct.
ArrayElementAsRefGets a reference to the array element at its current location in memory.
AsReinterprets the reference as a reference of a different type.
AsRefGets a reference to the struct at its current location in memory.
CheckForLeaksAny memory allocated before this call, that hasn't already been freed, is assumed to have leaked. Prints a list of leaks.
CopyObjectAddressToPtrAssigns an Object reference to a struct or pinned class. See Also: UnsafeUtility.PinGCObjectAndGetAddress.
CopyPtrToStructureCopies sizeof(T) bytes from ptr to output.
CopyStructureToPtrCopies sizeof(T) bytes from input to ptr.
EnumEqualsDetermines whether the specified enums are equal without boxing.
EnumToIntReturn integer representation of enum value without boxing.
ForgiveLeaksTells the leak checking system to ignore any memory allocations made up to that point - if they leak, they are forgiven.
FreeFree memory.
FreeTrackedFree memory with leak tracking.
GetFieldOffsetReturns the offset of the field relative struct or class it is contained in.
GetLeakDetectionModeGet whether leak detection is 1=disabled, 2=enabled, or 3=enabled with callstacks.
IsBlittableReturns whether the struct is blittable.
IsNativeContainerTypeReturns whether the struct or type is a Unity NativeContainer. A NativeContainer type uses the NativeContainerAttribute attribute.
IsUnmanagedReturns whether the struct or type is unmanaged. An unmanaged type contains no managed fields, and can be freely copied in memory.
IsValidAllocatorReturns true if the allocator label is valid and can be used to allocate or deallocate memory.
IsValidNativeContainerElementTypeReturns whether the type is acceptable as an element type in native containers.
MallocAllocate memory.
MallocTrackedAllocate memory with leak tracking.
MemClearClear memory.
MemCmpChecks to see whether two memory regions are identical or not by comparing a specified memory region in the first given memory buffer with the same region in the second given memory buffer.
MemCpyCopy memory.
MemCpyReplicateCopy memory and replicate.
MemCpyStrideSimilar to UnsafeUtility.MemCpy but can skip bytes via desinationStride and sourceStride.
MemMoveMove memory.
MemSetSet memory to specified value.
PinGCArrayAndGetDataAddressKeeps a strong GC reference to the object and pins it. The object is guranteed to not move its memory location in a moving GC. Returns the address of the first element of the array.See Also: UnsafeUtility.ReleaseGCObject.
PinGCObjectAndGetAddressKeeps a strong GC reference to the object and pins it. The object is guranteed to not move its memory location in a moving GC. Returns the address of the memory location of the object.See Also: UnsafeUtility.ReleaseGCObject.
ReadArrayElementRead array element.
ReadArrayElementWithStrideRead array element with stride.
ReleaseGCObjectReleases a GC Object Handle, previously aquired by UnsafeUtility.PinGCObjectAndGetAddress.
SetLeakDetectionModeSets whether leak detection is 1=disabled, 2=enabled, or 3=enabled with callstacks.
SizeOfSize of struct.
WriteArrayElementWrite array element.
WriteArrayElementWithStrideWrite array element with stride.
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961