Originally Posted by
Elysia
"a" is 2 bytes and a string object also keeps track of length, so I would say it takes up at least 2 + 4 + 4 = 10 bytes of memory.
An empty string takes up 8 or 9 bytes I would say. But it really depends on the implementation. I don't think there's any mention in the C++ standard as to what size the object should be.
(Size [unsigned integer, 4 bytes] + string [char pointer, 4 bytes] + string data [chars, 0 bytes+]).
So if we build on this, 9 bytes for an empty string = 9 * 1 000 000 bytes = ~8.5 MB.
(This does not take into account vector overhead for each element, if any.)