Skip to content

Commit c278933

Browse files
Update README.md
1 parent b1856e2 commit c278933

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,29 @@ Supported collections:
2929
- List
3030
- Queue
3131

32+
General idea (on the example of a list):
33+
Allocate memory for all your collections.
34+
35+
![1](https://user-images.githubusercontent.com/43916814/188752538-cff787a0-2c92-4d86-8439-6c9efec3eb57.png)
36+
37+
In our example, we will allocate a list of 5 elements on this memory.
38+
39+
![2](https://user-images.githubusercontent.com/43916814/188752689-bbc509e0-05be-4ea2-847f-5ba04ca5b066.png)
40+
41+
If we need to increase the dimension, and at the same time, the collection whose dimension increases is the last element in memory, then to increase the dimension, you just need to indicate that there is more available memory for the collection. No copying or reallocation.
42+
43+
![3](https://user-images.githubusercontent.com/43916814/188752910-11f87ccc-2384-4a9a-909c-91d85c2e67fa.png)
44+
45+
If we need to remove the element at index(4), then instead of allocating a new collection and copying the elements into new memory, we simply shift the elements 5,6 to the left by the amount of memory occupied by the element at index 4.
46+
47+
![4](https://user-images.githubusercontent.com/43916814/188753093-b6ff1a46-c05c-4b53-92ed-c88acfc30f37.png)
48+
49+
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.
50+
51+
If something else is written to memory after the collection, then the collection becomes sealed.
52+
In the future, you can compress memory if there are areas that are no longer used, thereby not sealing the collection.
53+
This can be useful for allocating memory for an entire method if we know approximately how much memory it can consume at the maximum.
54+
3255
Usage:
3356

3457
```C#

0 commit comments

Comments
 (0)