Open BeanCheeseBurrito opened 7 months ago
Allocating pinned arrays for managed types is only possible in .NET 8 and above. The minimum target version has been changed from .NET Standard 2.1 to .NET 8 in this PR https://github.com/BeanCheeseBurrito/Flecs.NET/pull/42. The Unity package will no longer be updated.
When pluggable storages are added to flecs, pinned C# arrays should be used as storage for managed types.
Performance - Special unboxing code is required per every iteration in the current design. Using plain C# arrays will remove this overhead and bring the performance of managed component iteration on par with native C# ECS frameworks/libraries.
Memory Allocations - This will greatly reduce memory consumption due to only needing a single
GCHandle
andBox<T>
object to be allocated per column instead of per component.Debugging - With the current setup, it is not possible to inspect the contents of a column for both managed and unmanaged types inside a debugger due to the
GCHandle
indirection and unboxing step required for managed objects. Switching to C# array storage will replace theColumn<T>
type with theSpan<T>
type and allow the contents of components to be displayed in the debugger.Pointer APIs - Pointer-based APIs in Flecs.NET are currently restricted to unmanaged types only. This restriction can be removed entirely as using pinned C# arrays will allow us to retrieve pointers to managed component references. This is a prerequisite to being able to properly implement serialization and deserialization for managed types.