You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If we need to increase the capacity, and at the same time, the collection whose capacity increases is the last element in memory, then to increase the capacity, you just need to indicate that there is more available memory for the collection. No copying or reallocation.
If we need to allocate a collection of elements of a different type on the same memory (and we do not need the old collection), then we do not have to allocate new memory, we can allocate it on the already allocated one.
52
+
In our example, we will allocate a list of 50 elements on this memory.
53
+
Then we increase the capacity to the 100 elements. No copying or reallocation.
54
+
Then we free old collection and allocate new collection of Int64 on the same memory.
47
55
48
-
If something else is written to memory after the collection, then the collection becomes sealed.
49
-
In the future, you can compress memory if there are areas that are no longer used, thereby not sealing the collection.
56
+
In the future(TODO), you can compress memory if there are areas that are no longer used, thereby not sealing the collection.
50
57
This can be useful for allocating memory for an entire method if we know approximately how much memory it can consume at the maximum.
51
58
52
-
Usage:
59
+
_____
60
+
Stack of composite type example:
53
61
54
62
```C#
55
63
//Marking a class/struct with attributes is all that is required of you.
56
64
[GenerateStack]
57
65
[GenerateWrapper]
58
-
publicstructJobStruct
66
+
publicstructSimpleStruct
67
+
{
68
+
publicSimpleStruct(
69
+
intint32,
70
+
longint64
71
+
)
72
+
{
73
+
Int32=int32;
74
+
Int64=int64;
75
+
}
76
+
77
+
publiclongInt64;
78
+
publicintInt32;
79
+
}
80
+
81
+
[GenerateStack]
82
+
[GenerateWrapper]
83
+
publicclassSimpleClass
59
84
{
60
-
publicJobStruct(
85
+
publicSimpleClass(
61
86
intint32,
62
87
longint64
63
88
)
@@ -76,57 +101,49 @@ public struct JobStruct
76
101
//Stack of pointers
77
102
unsafe
78
103
{
79
-
using (varmemory=newStruct.StackMemory(JobStructHelper.SizeOf+ (nuint)sizeof(IntPtr)))
104
+
using (varmemory=newStruct.StackMemory(SimpleStructHelper.SizeOf+ (nuint)sizeof(IntPtr)))
0 commit comments