https://github.com/webfreak001/cyclic
one-time allocation fixed memory nogc array implementation using a cyclic stack/malloc'd array with high efficiency putBack & putFront
https://github.com/webfreak001/cyclic
Last synced: 5 months ago
JSON representation
one-time allocation fixed memory nogc array implementation using a cyclic stack/malloc'd array with high efficiency putBack & putFront
- Host: GitHub
- URL: https://github.com/webfreak001/cyclic
- Owner: WebFreak001
- Created: 2017-12-13T23:03:07.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-12-19T21:33:26.000Z (over 8 years ago)
- Last Synced: 2025-02-28T14:48:12.586Z (over 1 year ago)
- Language: D
- Size: 7.81 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# cyclic
one-time allocation fixed memory nogc array implementation using a cyclic stack/malloc'd array with high efficiency putBack & putFront.
This is basically just a normal array without allocations and instead of having a continous stream of memory it can be cut off once.
Optimal for a dequeue with fairly reliable (but not guaranteed nor safe) multi-threaded access.
```d
// stack array, taking up to 4kb by default
CyclicArray!int array;
assert(array.length == 0);
array ~= 5;
assert(!array.empty);
assert(array.front == 5);
assert(array[0] == 5);
array ~= [4, 3];
assert(array == [5, 4, 3]);
// same efficiency as insertBack/put/concat
array.insertFront(5);
// heap array using std.container.Array with 16 elements
auto heapArray = CyclicArray!(int, 0)(16);
// custom memory using Array
auto myArray = Array!int(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
auto customArray = CyclicArray!(int, 0)(myArray[0 .. 6]);
```