项目作者: dasannikov

项目描述 :
Collection of native plugins for Unity3D with common data structures and zero allocations
高级语言: C#
项目地址: git://github.com/dasannikov/Vault.git
创建时间: 2020-02-10T18:14:07Z
项目社区:https://github.com/dasannikov/Vault

开源协议:MIT License

下载


Vault Libray for Unity3D

DOWNLOAD: Latest build (Unity package)

Vault.List - Continuous data array with dynamic size similar to C++ std::vector<T> or C# List<T>. It uses an optimized native array implemented on C that is even faster than STL C++ containers (apporix. 10% faster) and has zero C# memory allocations.

Supported platforms:

  • Standalone Mono. Windows/MacOS/Linux
  • Standalone IL2CPP. Windows/MacOS/Linux
  • Mobile. iOS/Android
  • Other through IL2CPP or specific shared libraries

Advantages:

  • Doesn’t use any Unity3D features. Can work with any C# code
  • Continuous data array with dynamic size
  • Fast and small prebuild native libraries
  • No C# memory allocations and C# GC
  • You manage your memory (Free means deleting container and releasing memory)

Usage

Vault.List is a continuous container with dynamic size. Similar to C++ std::vector<T> or C# List<T> or Unity’s NativeList<T>

  1. // New list with default initializer
  2. // Vault.List is a struct. Zero allocations in C# memory
  3. var vecArr = new Vault.List<Vector2>(10, new Vector2(1.0f, 1.0f));
  4. // Set element value
  5. vecArr[9] = new Vector2(101f, 102f);
  6. vecArr[0] = new Vector2(101f, 102f);
  7. // Resize list
  8. vecArr.Resize(14);
  9. // Add element to list.
  10. vecArr.Add(new Vector2(21f, 22f));
  11. // Fast remove element by swap with last element
  12. vecArr.RemoveBySwap(1);
  13. // Relatively slow remove element by memmove
  14. vecArr.Remove(1);
  15. // Swap elements
  16. vecArr.Swap(0, 1);
  17. // Clear list
  18. vecArr.Clear();
  19. // Free list after use
  20. // Completely release unmanaged memory
  21. vecArr.Free();

Performance

Performance (IL2CPP Builds) is similar (±10%) to Unit’s NativeList<T>