Closed guidoreina closed 3 years ago
Indeed, we used to grow the buffer exponentially, but that felt like overkill, given the library's intended use case (human I/O), so we simplified to just growing by 1 on each iteration, the overhead of which is negligible for the use case. So, good instincts, but conscious choice ultimately!
Thank you for your quick answer. You are right, for human input the buffer won't grow that much anyway. Thank you also for the CS50 videos, they are just great.
In the function get_string() there are two variables: capacity and size. It looks like the idea behind them is not to realloc() for every single character read, but in the while loop capacity is always incremented by 1 instead of by a bigger number or capacity * 2. This leads to realloc() being always called in each iteration, is this intentional?