On Wed, 2016-08-10 at 21:31 -0400, Trevor Saunders wrote: > > Well, I'd say the compromises made in std::string make it pretty > terrible for general purpose use accept where perf and memory doesn't > matter at all. > > std::vector isn't very great size wise either, imho the size / > capacity fields would be much better put in the buffer than in the > struct itself, to save 2 * sizeof (void *) in sizeof std::vector. There's nothing in the standard that says those fields have to go into the vector struct/class itself and not into the data buffer. It just happens to be the way it's implemented in libstdc++. E.g. libc++ implements some things in different ways to save a few bytes here and there. It looks more practical to put those fields into the container itself, otherwise you'd have to do a nullptr check every time you access the size field etc. Although newer compilers optimize away the redundant nullptr checks, older compilers (which GCC wants to be good with) might not do it. In any case, it seems to generate slightly bigger code, at least in one instance (see attachment). Anyway, normally there is more data in the vectors than there are vectors around, so whether sizeof (vector) is 8 or 24 bytes doesn't matter. > > or just having your stack_string type convert to the normal string > type so that you can pass mutable references. But that would imply copying, wouldn't it? Cheers, Oleg