Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



I 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




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: