BlobObject
A Unity object that stores a blob of contiguous bytes that jobs can read without copying the data.
読み終わるまでの所要時間 6 分最終更新 2日前
Definition
- Type: Class
- Namespace: UnityEngine
- Assembly: UnityEngine.AnimationModule
- Inherits from: Object
public class BlobObject : Object
Remarks
Jobs that the Burst compiler compiles can read the blob data in parallel through a BlobObjectReference<T>. Reading the data doesn't copy it, so reading is cheap enough for performance-critical code.
A is a Object, so it also benefits from the object management that Unity provides. The management includes garbage collection, deduplication of the instances that the same MonoBehaviour references, and authoring in the Unity Editor.
BlobObjectBlobObjectTo store data, call BlobObject.SetBlobAsset with a BlobAssetReference<T>. To read the data, call BlobObject.AcquireReference to get a reference, and dispose the reference when you finish with it. To read the data as a , call BlobObjectReference<T>.AsBlobAssetReference on the reference.
BlobAssetReferenceThe following example uses the , , , and namespaces. It stores a custom blob in a , reads the data back through a , and then disposes the reference and destroys the object.
Unity.AnimationsUnity.CollectionsUnity.EntitiesUnityEngineBlobObjectBlobObjectReferenceAdditional Resources: BlobObjectReference<T>
Examples
// This example stores marker times in a BlobObject, reads them back through a reference, and sums them.// A custom blob type can hold only unmanaged data, such as values and BlobArray fields.public struct MarkerTable{ public BlobArray<float> Times;}public static float StoreAndSumMarkerTimes(float[] markerTimes){ const int version = 1; // Build the blob asset. SetBlobAsset copies it, so you can dispose the original afterwards. BlobObject blobObject = new BlobObject(); using (BlobBuilder blobBuilder = new BlobBuilder(Allocator.Temp)) { ref MarkerTable root = ref blobBuilder.ConstructRoot<MarkerTable>(); BlobBuilderArray<float> times = blobBuilder.Allocate(ref root.Times, markerTimes.Length); for (int i = 0; i < markerTimes.Length; ++i) { times[i] = markerTimes[i]; } using (BlobAssetReference<MarkerTable> blobAsset = blobBuilder.CreateBlobAssetReference<MarkerTable>(Allocator.Temp)) { blobObject.SetBlobAsset(blobAsset, version); } } // Acquire a reference with the same version. The data stays alive until you dispose the reference. BlobObjectReference<MarkerTable> reference = blobObject.AcquireReference<MarkerTable>(version); // Read the data. The returned blob asset reference is a view of the stored data, so don't dispose this blob asset reference. BlobAssetReference<MarkerTable> markerTable = reference.AsBlobAssetReference(); float sum = 0f; ref MarkerTable table = ref markerTable.Value; for (int i = 0; i < table.Times.Length; ++i) { sum += table.Times[i]; } // Dispose the reference, then destroy the object. reference.Dispose(); Object.DestroyImmediate(blobObject); return sum;}
Constructors
Constructor | Description |
|---|---|
| BlobObject() | Creates an empty BlobObject. |
Methods
Method | Description |
|---|---|
| AcquireReference | Acquires a reference that keeps the blob data stored in this object alive, even if the object is destroyed or its data is replaced. |
| SetBlobAsset | Replaces the data stored in this object with a copy of a blob asset. |
| SetUntypedBlobData | Replaces the data stored in this object with a copy of the given data, type hash, and version. |
| TryGetUntypedBlobData | Gets the data stored in this object without checking its type or version, for example to migrate data written with an older layout. |
Inheritance
Operators
Operator | Description |
|---|---|
| operator == | Compares two object references to see if they refer to the same object. |
| bool | Determines whether the object exists. |
| operator != | Compares if two objects refer to a different object. |