Re: Mixing size_t and other types




"Navaneeth" <navaneethkn@xxxxxxxxx> wrote in message
news:032d39b2-ced3-445d-a2aa-f070d3af4d20@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
It looks like precalculating the filesize is not a good idea. A better
approach would be to read each charater and allocate necessary memory
using "realloc". So I don't have all these size_t and other type
mixing issues.

in the cases where the long/size_t issue will actually matter, malloc and
realloc will likely fail as well...

note that expandable buffer sizing is a problem to get right (unless one
knows how to do it well), as doing it poorly will typically fragment memory
and cause poor performance.

my usual strategy though is to always just expand the buffer by 50% (from
its current size) whenever it needs to expand, which typically works well
enough.


.