Re:Please grow your buffers exponentially
by reubenmorais on Tuesday November 04, 2014 @02:33PM
(#8558561)
>I thought Firefox was mostly written in C++? Pretty surprised that raw realloc()s are widespread enough to warrant a note like this.
It is, but STL usage is very limited, because of all the headaches involved in linking against all the different STL implementations in all the different platforms. mozilla-central has its own containers.
Re:Please grow your buffers exponentially
by ExpiredLink on Tuesday November 04, 2014 @03:44PM
(#8558932)
The C++ variant most used in the real world is 'C with (some) classes'.
Re:Please grow your buffers exponentially
by cerberusss on Wednesday November 05, 2014 @02:45AM
(#8560873)
That, or people stay put in a framework such as Qt. I'd consider myself an experienced Qt developer. C++? Not so much.
I understand, but writing your own dynamic resizing array class is not hard.
Re:Please grow your buffers exponentially
by nnethercote on Tuesday November 04, 2014 @05:13PM
(#8559381)
> Pretty surprised that raw realloc()s are widespread enough to warrant a note like this.
Firefox is a large, old codebase. After working on it for a while you stop being surprised by almost anything :)
Re:Please grow your buffers exponentially
by frozenport on Tuesday November 04, 2014 @10:56AM
(#8557155)
I wonder if an STD vector would have similar performance, if you preallocated the memory on creation but still used standard library functions for code readability?
I agree that it's better to know how much space you need up front - even if it turns a one-pass algorithm into a two-pass one.
One of my happiest moments as a programmer came when reading a co-worker's code to render 2d parametric functions smoothly in screen space. It recursively divides down the parameter interval until it's small enough, then draws line segments. The code is written iteratively and manually manages a stack to simulate recursion. The stack is a fixed-size static C array instead of a vector. "Aren't you worried about overflow?", I asked. But he had computed the number of divisions in half to get from a FLT_MAX-length interval down to an FLT_MIN-length interval, and made the array big enough to hold that many steps. Goodbye malloc(), hello one not-really-that-big static array that stays warm in the cache.