4 ms·
Preallocating beat reallocating? You don't say! The context of this post is when you are implementing a growable abstraction like a string or vector. When yo
by haberman 12y ago
Preallocating beat reallocating? You don't say!
The context of this post is when you are implementing a growable abstraction like a string or vector. When you are the library, you have no reasonable way of guessing how big it will ultimately grow. At the application layer, of course you have better options available.
- jonstewart 12y agoI was writing a library. I gave the user the option to provide me with the initial preallocation size, and a good method for guessing it. When libraries deal with lots of things, it's generally important to expose special handling for dealing with lots of things. Jon