Hugh McMaster hugh.mcmaster@outlook.com writes:
The initial size won't make a difference, the problem is that you always append data without removing it, so the buffer grows to the entire file size. It shouldn't need to grow bigger than the longest line.
Continually moving the remaining characters to the start of the buffer hits perfomance. That's why I took the 'read into memory' approach as line parsing is faster in RAM.
But fair enough, I'll rework the patch. Still, I'm interested to know why you dislike reading the file into memory first.
It's wasteful, it doesn't scale, and there's no reason to do it since you only read one line at a time. And I very much doubt that with the reallocations and the extra memory pressure performance would be any better.