Re: slurping in binary data
- From: Nate Eldredge <nate@xxxxxxxxxx>
- Date: Thu, 20 Nov 2008 10:45:13 -0800
James Kuyper <jameskuyper@xxxxxxxxxxx> writes:
My biggest problem with ggets() is the lack of support for re-using
buffers that have already been allocated. On those rare occasions when
I want to do anything remotely similar to ggets(), I usually use a
single-line buffer which I realloc() to a larger size whenever a line
comes in which is too big for the current buffer size. I almost never
want to waste time allocating a brand new buffer for every single line
of the input file.
I'll put in a plug for something like the getline() function from glibc.
ssize_t getline (char **LINEPTR, size_t *N, FILE *STREAM);
*LINEPTR should be a pointer to a buffer of size *N obtained from
malloc. If it is not large enough, it's expanded with realloc, and
*LINEPTR and *N are updated appropriately.
It's very easy to write your own version in standard C, of course.
Unfortunately glibc's code is tightly wound in with the rest of their
stdio library, otherwise it could be swiped and used verbatim in a GPL
program.
.
- Follow-Ups:
- Re: slurping in binary data
- From: pete
- Re: slurping in binary data
- From: George
- Re: slurping in binary data
- References:
- slurping in binary data
- From: George
- Re: slurping in binary data
- From: Nick Keighley
- Re: slurping in binary data
- From: George
- Re: slurping in binary data
- From: James Kuyper
- Re: slurping in binary data
- From: George
- Re: slurping in binary data
- From: James Kuyper
- Re: slurping in binary data
- From: George
- Re: slurping in binary data
- From: James Kuyper
- Re: slurping in binary data
- From: Richard Heathfield
- Re: slurping in binary data
- From: James Kuyper
- slurping in binary data
- Prev by Date: Re: What is this?
- Next by Date: Re: Simple MD5 Hash - Different output on different OS
- Previous by thread: Re: slurping in binary data
- Next by thread: Re: slurping in binary data
- Index(es):
Relevant Pages
|