Arch.LowLevel

Arch.LowLevel, a collection of unmanaged and unsafe collections.

Arch.Extended also has a number of high-performance, unsafe collections and utils. They are mostly blittable, unmanaged and use pointers directly to access memory. This has the advantage that they are fast and not affected by the GC.

Data-structures:

  • UnsafeArray<T>

  • UnsafeList<T>

  • UnsafeStack<T>

  • UnsafeQueue<T>

  • UnsafeJaggedArray<T>

  • JaggedArray<T>

  • SparseJaggedArray<T>

Name
Purpose
Unmanaged & Blittable

UnsafeArray<T>

An unmanaged Array.

UnsafeList<T>

An unmanaged List.

UnsafeStack<T>

An unmanaged Stack.

UnsafeQueue<T>

An unmanaged Queue.

UnsafeJaggedArray<T>

An unmanaged JaggedArray, made out of buckets.

UnsafeSparseJaggedArray<T>

An unmanaged SparseJaggedArray, made out of buckets.

JaggedArray<T>

A managed JaggedArray, made out of buckets.

SparseJaggedArray<T>

A managed SparseJaggedArray, made out of buckets.

Array

A class that either stores its items automatically in an UnsafeArray or an managed Array.

Resources

A class that stores managed items and returns a Handle<T>to reference them in components.

Examples

The use of collections is actually a matter of course. Nevertheless, let's take a look at the most important ones.

Array

// Create (Using automatically disposes)
using var array = new UnsafeArray<int>(8);
array[0] = 0;
array[1] = 1;

// Acess
ref var intRef = ref array[0];

// Iterate
foreach(ref var item in array){
   Console.WriteLine(item);
}    

List

// Create (Using automatically disposes)
using var list = new UnsafeList<int>(8);
list.Add(1);
list.Add(2);

// Acess
ref var intRef = ref list[0];

// Iterate
foreach(ref var item in list){
   Console.WriteLine(item);
}    

Resources

Thanks to the Resources, you can access and use a managed resource from anywhere using a unique ID. This saves memory and is blittable, so it can also be used in unsafe code.

// Create resources jagged array and create a sprite handle
var resources = new Resources<Sprite>(IntPtr.Size, capacity: 64);
var handle = resources.Add(new Sprite());
var sprite = resources.Get(in handle);

// Use handle wherever you want to access the sprite
public struct SpriteComponent{
   public Handle<Sprite> handle;
}

Last updated

Was this helpful?