Re: Mixing size_t and other types
- From: "BGB / cr88192" <cr88192@xxxxxxxxxxx>
- Date: Sun, 1 Aug 2010 14:17:32 -0700
"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.
.
- Follow-Ups:
- Re: Mixing size_t and other types
- From: Nobody
- Re: Mixing size_t and other types
- References:
- Mixing size_t and other types
- From: Navaneeth
- Re: Mixing size_t and other types
- From: Ian Collins
- Re: Mixing size_t and other types
- From: Navaneeth
- Re: Mixing size_t and other types
- From: chrisbazley
- Re: Mixing size_t and other types
- From: Navaneeth
- Mixing size_t and other types
- Prev by Date: Re: Mixing size_t and other types
- Next by Date: Re: Mixing size_t and other types
- Previous by thread: Re: Mixing size_t and other types
- Next by thread: Re: Mixing size_t and other types
- Index(es):