Optimize UnboxValue performance, safety and memory usage

- Avoids unnecessary boxing of the converted values by storing them in
unmanaged memory.
- Wrap ToNative-method in a delegate and cache it
- Fixes returning address to unpinned memory by pinning POD-types for
a short period of time.
This commit is contained in:
2023-08-13 14:18:57 +03:00
parent 09be2375f6
commit 1254af8bbb
2 changed files with 49 additions and 15 deletions

View File

@@ -650,7 +650,6 @@ namespace FlaxEngine.Interop
if (!type.IsValueType)
return ManagedHandle.ToIntPtr(handle);
// HACK: Get the address of a non-pinned value
return ValueTypeUnboxer.GetPointer(value, type);
}