> Growing your array by only a constant amount each iteration takes > quadratic time. By instead doubling the array size each time as > necessary, you can reduce this to (amortized) linear time. (I believe > the man page's intention was to show how to avoid leaking memory, not > how to write an efficient program.)
See 'makespace' in http://www.gtoal.com/compilers101/tinc/02_Graham_Toal/teeny.c for an example of a generic way to do this. You call makespace each time you access your flex array with an index, and it will make sure the array is large enough such that the element with that index is present. (You don't need to call it if you know that the index is smaller than the largest index you've already accessed, but for safety it might be good practice to call it before every array access - the overhead isn't too high) You could probably use the preprocessor to hide it entirely, and just access your array with a macro, eg i = tickdata(n); rather than i = tickdata[n]; and have the macro first call makespace... G