Re: Character Vector vs. String (in STL)
Al <two@haik.us> wrote:
1) Are there major conceptual differences between:
std::vector<char> and std::string?
(or std::vector<wchar_t> / std::wstring)
2) Is it possible/likely that these are implemented equally behind the
scenes?
3) Is there any performance data available using one versus the other in
different scenarios (e.g. quick short strings and long text files)?
4) Is either optimized for specific situations?
All of the above are very platform specific questions.
Until recently, there was no guarantee that a string was implemented
with contiguous memory (i.e., it could have been implemented more like a
deque,) but that is now changed as I understand it. std::string is
guaranteed to be implemented with contiguous memory now.
There was also a time when many std::string classes were implemented
with a copy-on-write strategy, but it was found that performance
suffered in multi-threaded applications which such a string.
The only difference between vector<char> and string any more AFAIK is
the use of the "small string optimization". A method for getting around
the allocation of memory if the string only contains 'x' characters or
less (where 'x' is some number decided on by the vendor as optimal.)
It is reasonable to assume that any decent sized application that deals
heavily with string data, will have more than one implementation of
'string' depending on what the various strings are being used for.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]