Skip to content

Commit 8a6e419

Browse files
Update README.md
1 parent 3237ffa commit 8a6e419

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,87 @@ Supported collections:
1414
- List [TODO](https://github.com/SoftStoneDevelop/StackMemoryCollections/issues/1)
1515
- Queue [TODO](https://github.com/SoftStoneDevelop/StackMemoryCollections/issues/2)
1616

17+
Usage:
18+
19+
```C#
20+
//Marking a class/struct with attributes is all that is required of you.
21+
[GenerateHelper]
22+
[GenerateStack]
23+
[GenerateWrapper]
24+
public struct JobStruct
25+
{
26+
public JobStruct(
27+
int int32,
28+
long int64
29+
)
30+
{
31+
Int32 = int32;
32+
Int64 = int64;
33+
JobStruct2 = default;
34+
}
35+
36+
public long Int64;
37+
public int Int32;
38+
public JobStruct2 JobStruct2;
39+
}
40+
41+
```
42+
43+
```C#
44+
//Stack of pointers
45+
unsafe
46+
{
47+
using (var memory = new StackMemoryCollections.Struct.StackMemory(JobStructHelper.GetSize() + (nuint)sizeof(IntPtr)))
48+
{
49+
using var stack = new StackMemoryCollections.Struct.StackOfIntPtr(1, &memory);
50+
{
51+
var item = new Struct.JobStructWrapper(&memory);
52+
item.Int32 = 456;
53+
stack.Push(new IntPtr(item.Ptr));
54+
}
55+
var item2 = new Struct.JobStructWrapper(stack.Top().ToPointer());
56+
//item2 point to same memory as is item
57+
}
58+
}
59+
```
60+
61+
```C#
62+
//Stack of structures
63+
//All alocate memory = JobStructHelper.GetSize() * (nuint)100)
64+
unsafe
65+
{
66+
using (var memory = new StackMemoryCollections.Struct.StackMemory(JobStructHelper.GetSize() * (nuint)100))//allocate memory
67+
{
68+
var item = new JobStruct(0, 0);
69+
70+
{
71+
using var stack = new Benchmark.Struct.StackOfJobStruct((nuint)Size, &memory);//get memory
72+
for (int i = 0; i < Size; i++)
73+
{
74+
item.Int32 = i;
75+
item.Int64 = i * 2;
76+
item.JobStruct2.Int32 = 15;
77+
item.JobStruct2.Int64 = 36;
78+
stack.Push(in item);
79+
}
80+
81+
//Do whatever you want with stack
82+
}//return memory
83+
84+
var stack2 = new Benchmark.Struct.StackOfJobStruct((nuint)Size, &memory);//get memory
85+
for (int i = 0; i < 100; i++)
86+
{
87+
item.Int32 = i;
88+
item.Int64 = i * 2;
89+
item.JobStruct2.Int32 = 15;
90+
item.JobStruct2.Int64 = 36;
91+
stack2.Push(in item);
92+
}
93+
}//free all memory
94+
}
95+
96+
```
97+
1798
## Benchmarks:
1899

19100
<details><summary>Stack</summary>

0 commit comments

Comments
 (0)