Re: slurping in binary data



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.
.



Relevant Pages

  • Re: Changing output buffer size in dsp plugin
    ... HRESULT ProcessOutput( ... into it, process it, and return the new buffer to ProcessOutput. ... > therefore I need to find a way to realloc this output stream so it matches ... > 2) deallocating and allocating in the AllocateStreamingResources ...
    (microsoft.public.windowsmedia.sdk)
  • Changing output buffer size in dsp plugin
    ... I have created a plugin which is able both to increase and decrease the ... length of the buffer. ... therefore I need to find a way to realloc this output stream so it matches ... deallocating and allocating in the AllocateStreamingResources ...
    (microsoft.public.windowsmedia.sdk)
  • Re: Buffer or Realloc?
    ... better to allocate memory and realloc it for the size of the what is ... between deciding to use a fixed size buffer or allocating memory ...
    (comp.lang.c)
  • Re: [PATCHSET] printk: implement printk_header() and merging printk, take #3
    ... result TF isn't available and thus res printout is ... require allocating yest another temp buf and separating out res printing ... needed to allocate the buffer elsewhere than stack. ...
    (Linux-Kernel)
  • Re: String data input and storage
    ... As you can probably tell I dont have much coding practice, but I am trying to get there. ... saving some by not allocating memory that you will not be using. ... stdin kernel buffer into your process's buffer, ...
    (comp.lang.c)