On Sep 22, 2011 7:37 PM, "Fraser Adams" <[email protected]> wrote: > What's the case for saying that using std::string as a container for binary data is a good idea? Just because it's common doesn't make necessarily make it a great thing. To me it seems inappropriate and there are other containers that seem more valid for binary data. Perhaps it's just me, but I certainly see a string as a sequence of characters - in other words textual data.
Not sure why is that. I guess it's because it makes things easy by allowing fast pass-by-value, which means you don't have to worry about memory ownership like when passing around char pointers. From that perspective you could see std::string as something like a shared array of bytes. (Assuming the implementation of std::string uses copy-on-write semantics.)
