Re: [dev] print utility

From: Sam Watkins <sam_AT_nipl.net>
Date: Fri, 5 Apr 2013 12:44:11 +1100

On Thu, Apr 04, 2013 at 09:30:49AM +0200, Martti K??hne wrote:
> On Sun, Mar 31, 2013 at 4:53 AM, Calvin Morrison <mutantturkey_AT_gmail.com> wrote:
> > Forget this whole LINE_MAX thing, I am looking at your suggestion in
> > the other message.
>
> For line buffering, I also use char arrays

I tend to use either a char array (and long line -> error) or a 'double on
full' malloc'd char 'vector'. That's somewhat inefficient with the memory
but seems to be a good approach when you don't know how big the line or
bloc is going to be. It only has to move memory log(n) times, which is
not too bad. Moving total cost is O(n). But there can be high latency
for appending a single char if it needs to realloc.

Can also use some list of buffers ala readv / writev, but then it's not
cstr compatible and have to write new functions for simple things like
searching in it.

Kernighan and Pike implement that 'double on full' approach in
'the Practise of Programming' for one of their examples, so I guess it's
legit. This approach could be used for C++ std::vector, requires append
to be O(1) on average, not for each append individually.

Sam
Received on Fri Apr 05 2013 - 03:44:11 CEST

This archive was generated by hypermail 2.3.0 : Fri Apr 05 2013 - 03:48:05 CEST