Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Readme.md

Definition

Represents a simple last-in-first-out (LIFO) collection of {ItemType}. Where ItemType is you class/struct name. The collection is auto-generated, for generation the class/struct {ItemType} must be marked with the attribute [GenerateStack].

For class/struct items:

Class

namespace {ItemTypeNamespace}.Class
{
    public unsafe class StackOf{ItemType} : IDisposable, System.Collections.Generic.IEnumerable<{ItemType}>
}

Implements IEnumerable<{ItemType}>, IEnumerable, IDisposable

Struct

namespace {ItemTypeNamespace}.Struct
{
    public unsafe struct StackOf{ItemType} : IDisposable
}

For primitive types:

Int32, Int64, UInt32... and IntPtr. Class

namespace StackMemoryCollections.Class
{
    public unsafe class StackOf{PrimitiveType} : IDisposable, System.Collections.Generic.IEnumerable<{PrimitiveType}>
}

Implements IEnumerable<{PrimitiveType}>, IEnumerable, IDisposable

Struct

namespace StackMemoryCollections.Struct
{
    public unsafe struct StackOf{PrimitiveType} : IDisposable
}

Implements IDisposable

Constructors

Name ForType
StackOf{ItemType}() All
StackOf{ItemType}(nuint, Struct.StackMemory*) All
StackOf{ItemType}(nuint, Class.StackMemory) All
StackOf{ItemType}(nuint, void*) All

Properties

Name ForType
Capacity All
Size All
Start All
IsEmpty All

Methods

Name ForType
ReducingCapacity(in nuint) All
ExpandCapacity(in nuint) All
TryExpandCapacity(in nuint) All
TrimExcess() All
Push(in {ItemType}) All
Push(in void*) All
TryPush(in {ItemType}) All
TryPush(in void*) All
PushFuture() All
Pop() All
TryPop() All
Clear() All
Top() All
Top(in void*) All
Top(ref {ItemType}) All
TopPtr() All
TopFuture() All
TopOut(out {ItemType}) All
[nuint] All
Copy(in void*) All
Copy(in void*, nuint) All
Copy(in Class.StackOf{ItemType}) All
IEnumerator<{ItemType}> GetEnumerator() Class
IEnumerable GetEnumerator() Class
Dispose() All

Examples

[GenerateStack]
public struct JobStruct
{
    public JobStruct(
        int int32,
        long int64
        )
    {
        Int32 = int32;
        Int64 = int64;
    }

    public long Int64;
    public int Int32;
}

unsafe
{
    using (var memory = new Struct.StackMemory(JobStructHelper.SizeOf * (nuint)5))
    {
        var item = new JobStruct(0, 0);
        using var stack = new Struct.StackOfJobStruct((nuint)5, &memory);
        for (int i = 0; i < 3; i++)
        {
            item.Int32 = i;
            item.Int64 = i * 2;
            stack.Push(in item);
        }

        stack.TrimExcess();//No copy just pointer offset
        while (stack.TryPop())
        {
        }
    }
}
unsafe
{
    using (var memory = new Struct.StackMemory(JobStructHelper.SizeOf * (nuint)10))
    {
        var item = new JobStruct(0, 0);
        using var stack = new Struct.StackOfJobStruct((nuint)5, &memory);
        for (int i = 0; i < 10; i++)
        {
            item.Int32 = i;
            item.Int64 = i * 2;
            
            if(!stack.TryPush(in item))
            {
                stack.ExpandCapacity(1);//No copy just pointer offset
                stack.Push(in item);
            }
        }

        while (stack.TryPop())
        {
        }
    }
}