Re: [PATCH V2 3/3] strbuf: allow to use preallocated memory
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jun 8, 2016, 19:48 UTC
- Message-ID
- <xmqq37onlawb.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <20160608191918.GB19572@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 7 quoted lines
> That made me wonder if we could repeatedly reuse a buffer attached to > the file descriptor. And indeed, isn't that what stdio is? The whole > reason this buffer exists is because we are using a direct descriptor > write. If we switched this function to use fprintf(), we'd avoid the > whole buffer question, have a fixed cap on our memory use (since we just > flush anytime the buffer is full) _and_ we'd reduce the number of > write syscalls we're making by almost a factor of 100.
The primary reason why we avoid stdio in the lower level part of I/O is that the error reporting and handling is horrible.
e.g. c.f. http://article.gmane.org/gmane.comp.version-control.git/27019
Otherwise, I'd agree with your "Why aren't we using stdio if counting and avoiding overflow is so hard?".