Re:Please grow your buffers exponentially
by cakoose on Tuesday November 04, 2014 @06:18AM
(#8556003)
Let's say you start with a small array, then add N elements, one by one. When you run out of space in your underlying, you allocate a newer array, copy all the elements over, then free the old array.
If your new array is always a constant size bigger than the old one, then the total amount of work you do is O(n^2). If your new array is a constant factor bigger than the old one, the total amount of work you do is O(n).
This is ignoring memory allocator costs, which can change things a bit.
If your new array is always a constant size bigger than the old one, then the total amount of work you do is O(n^2). If your new array is a constant factor bigger than the old one, the total amount of work you do is O(n).
This is ignoring memory allocator costs, which can change things a bit.