I like the idea of having first class support of a fixed size dynamic array in the language, because I use Small_Array a lot and prefer it over the standard dynamic array.
I was just wondering how to use the new feature in practice. Is [dynamic; N] just syntactic sugar for a struct containing a compile time known array and a counter (instead of a pointer to an array)? Do you need to provide any form of allocator, or is it stack allocated by default? So one should use new/free to get a pointer, instead of make/delete for this collection type?
Do you need to provide any form of allocator, or is it stack allocated by default? So one should use new/free to get a pointer, instead of make/delete for this collection type?
As per the raw type definition, it is stack allocated and there’s no allocator stored, so you’d need to new()/free() it if you want to have it on the heap.
Thank you very much. This type is a super useful addition. Have you considered using a different keyword instead of “dynamic”? Because it could be a challenge to differentiate in the documentation eg.: Overview | Odin Programming Language
I didn’t want to add yet another keyword. It is a “dynamic” array but its memory is inline and of a fixed-capacity. So it makes sense to keep the syntax similar and to use the same keyword.
All of the operations like len, append, resize, work with the fixed capacity dynamic arrays, then it is clearer that it is actually akin to a dynamic array already.