mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-26 21:01:15 -05:00
MemoryをNativeArrayにコピーするときポインターを介することでコピーを削減
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"allowUnsafeCode": true,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Collections;
|
||||
using System.Runtime.InteropServices;
|
||||
using Unity.Collections.LowLevel.Unsafe;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
@@ -89,11 +90,17 @@ namespace UniGLTF
|
||||
|
||||
public NativeArray<T> CreateNativeArray<T>(ReadOnlyMemory<T> data) where T : struct
|
||||
{
|
||||
var array = CreateNativeArray<T>(data.Length);
|
||||
var toSpan = array.AsSpan();
|
||||
var fromSpan = data.Span;
|
||||
fromSpan.CopyTo(toSpan);
|
||||
return array;
|
||||
unsafe
|
||||
{
|
||||
var handle = data.Pin();
|
||||
var nativeArray = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray<T>(handle.Pointer, data.Length, Allocator.Persistent);
|
||||
m_disposables.Add(nativeArray);
|
||||
m_disposables.Add(handle);
|
||||
#if ENABLE_UNITY_COLLECTIONS_CHECKS
|
||||
NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref nativeArray, AtomicSafetyHandle.Create());
|
||||
#endif
|
||||
return nativeArray;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user