small string optimization for vector?
Posted
by BuschnicK
on Stack Overflow
See other posts from Stack Overflow
or by BuschnicK
Published on 2010-02-01T16:32:33Z
Indexed on
2010/03/14
18:25 UTC
Read the original article
Hit count: 216
I know several (all?) STL implementations implement a "small string" optimization where instead of storing the usual 3 pointers for begin, end and capacity a string will store the actual character data in the memory used for the pointers if sizeof(characters) <= sizeof(pointers). I am in a situation where I have lots of small vectors with an element size <= sizeof(pointer). I cannot use fixed size arrays, since the vectors need to be able to resize dynamically and may potentially grow quite large. However, the median (not mean) size of the vectors will only be 4-12 bytes. So a "small string" optimization adapted to vectors would be quite useful to me. Does such a thing exist?
I'm thinking about rolling my own by simply brute force converting a vector to a string, i.e. providing a vector interface to a string. Good idea?
© Stack Overflow or respective owner