4 ms·
What is the difference between this "small" vector and a vector?
by bullen 7y ago
What is the difference between this "small" vector and a vector?
- QuadDamaged 7y ago`SmallVec` allocates a contiguous array in the struct holding the vector itself (so it can be located on the stack), then if the capacity is insufficent, fallbacks to a heap-allocated `Vec` equivalent. The `Vec` struct contains the capacity and used length integers, as well as a pointer to the heap-allocated storage.
- PixelOfDeath 7y agoThe small vector class contains a static array of a few bytes. And as long as your data fits in it, no extra heap allocation is needed. A vector always does heap allocation, even if you only use a few bytes.
- Vogtinator 7y agoSounds like small string optimization (SSO), which is common in C++.
- bullen 7y agoOk, thx! If I use the trick Niklas calls “array with holes” in part 1, will each hole larger than the cache frame result in a cache miss?