linux - the dynamic array in C -
recently found annoyed deal array in c language.
have realloc() increase size.
, there no standard data structure vector in c++ or arraylist in java
have got known in linux kernel, there data structure, such
kfifo, use kfifo_in(), kfifo_out() function.
means user define kfifo *pointer; record array, , variable not contain info type contained in structure.
user have remember when try use dynamic array kfifo pointer.
think may little confusing.
there better way deal problem? what's common solution in linux c programing?
realloc
not bad, long not spread on code, , use reasonable strategy grow dynamic array.
rolling own dynamic arrays in c matter of implementing handful of easy functions. numerous short articles walk through exercise - here one example. article defines struct
represents dynamic array, along used , allocated size. provides functions initializing, growing, , de-allocating array represented structure. there no explicit initialization function in library - initialize passing null
first parameter. valid approach, opt more traditional separation of init
, grow
.
Comments
Post a Comment