comment on this page (Help on editing)


This page was imported from my old site and is yet to be reviewed.

My first stab at this worked by reading the entire directory into a heap-allocated buffer and iterating over it in memory.

However, the approach given here is much simpler: rather than invoke malloc, I iteratively read in 16 bytes to a stack-allocated buffer.

Where possible, I like to avoid memory allocation. In this case, the trade-off is potentially speed: lots of little fread() calls to save us invoking malloc.

However, its quite possible that the fread() call overhead would disappear behind internal buffering. In addition, the one malloc() call is very expensive where the directory size is significantly less than the malloc() implementation's minimum allocation size.

Back

This page is a draft.