A generic dynamic array in C that stores no capacity and needs no struct
1–10 of 38 posts
Re: A generic dynamic array in C that stores no capacity and needs no struct
#2No structs, just an array that accomplishes the same thing, without field names or other niceties. Enjoy the pleasure of not using a struct when you inevitably add/reduce/reorder fields later.
Re: A generic dynamic array in C that stores no capacity and needs no struct
#3https://github.com/gritzko/libabc/blob/main/Sx.h
https://github.com/gritzko/libabc/blob/main/S.md
ABC uses s[2] for slices, g[3] for gauges, b[4] for (ring) buffers. Also containers on top of those (heaps, hash sets, etc etc)
Re: A generic dynamic array in C that stores no capacity and needs no struct
#4No structs, just an array that accomplishes the same thing, without field names or other niceties. Enjoy the pleasure of not using a struct when you inevitably add/reduce/reorder fields later.
[dead]
Re: A generic dynamic array in C that stores no capacity and needs no struct
#5capacity isn't stored at all. Instead, it's computed on demand when the length of the vec is either zero or a power of two.
Brilliant insight. This is the first time I've seen this observation in over 3 decades of working with C.
Re: A generic dynamic array in C that stores no capacity and needs no struct
#6That's pretty clever code. Too clever for my tastes.
Re: A generic dynamic array in C that stores no capacity and needs no struct
#7[deleted]
Re: A generic dynamic array in C that stores no capacity and needs no struct
#8This is just silly. You can't even reserve capacity because you only store size and capacity is implicitly the next power of 2 >= size.
Re: A generic dynamic array in C that stores no capacity and needs no struct
#9[deleted]
Re: A generic dynamic array in C that stores no capacity and needs no struct
#10Strictly speaking, the capacity is still stored internally to the allocation (it needs to be, in order to implement realloc)