Generic dynamic array in 60 lines of C
gist.github.com
Generic dynamic array in 60 lines of C
1–10 of 110 posts
Re: Generic dynamic array in 60 lines of C
#2Re: Generic dynamic array in 60 lines of C
#3data (startptr), endptr & capacity?! Memory might be cheap enough to waste, but more derefs do not help timings.
Re: Generic dynamic array in 60 lines of C
#4data (startptr), endptr & capacity?! Memory might be cheap enough to waste, but more derefs do not help timings.
No checking malloc or realloc though. The anonymous struct is dubious too, though maybe being unable to pass these things to functions is a feature.
Re: Generic dynamic array in 60 lines of C
#5Re: Generic dynamic array in 60 lines of C
#6Re: Generic dynamic array in 60 lines of C
#7data (startptr), endptr & capacity?! Memory might be cheap enough to waste, but more derefs do not help timings.
Three pointers (or two and a size, or one and two sizes) is pretty standard for dynamic arrays. It lets you allocate more than one element a time when repeatedly appending one element. No checking malloc or realloc though. The anonymous struct is dubious too, though maybe being unable to pass these things to functions is a feature.
however, you can still do that, if you really want.
just `typedef DYN_ARR_OF(widget) widget_array;` and now you have a name-able type, and can even have dynamic-arrays-of-dynamic-arrays (`DYN_ARR_OF(widget_array)`).
Re: Generic dynamic array in 60 lines of C
#8Re: Generic dynamic array in 60 lines of C
#9Heavy use of macros to do metaprogramming is a strong sign it's time to move to a more powerful language.