Article
After implementing strings , I implemented dynamic arrays in C and wrote an article about it. The implementation is generic, I talk about the trade-offs of this approach in the article.
If you only care about the code, it's here.
Tell me what you think!
4
u/Physical_Dare8553 Sep 08 '26
i must always mention my own, incredibly hacro-heavy, but it's almost perfectly generic imo
2
u/realdreamer1993 Sep 09 '26
thanks for sharing and make me to dig something and open a path.
I am still not fluent in C but this trigger me to compare with my own code , I think I am using different technique which called hash table. And I research a little of knowledge about trade off comparison between dynamic array vs hash table vs linked list.
1
u/Last-Employ-3422 Sep 08 '26
Oh this reminds me of stb_ds.h
1
u/Maqi-X Sep 12 '26
Storing void pointers and the element size as a runtime value is really not a good idea. It is hard and bugprone to use, non type safe, sometimes requires you to do more dynamic allocation that you actually need to and it's likely slower than alternative approaches a
voidpointer in C is not an "any type". I suggest checking out https://github.com/lazzy-cipher/vector.h (Probably my favorite vector implementation for C) and https://github.com/eteran/c-vector0
u/[deleted] Sep 09 '26
[deleted] — view deleted comment