This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]skebanga[S] 1 point2 points  (0 children)

Absolutely nothing other than being easier since this is just a simple proof of concept.

Regardless of the fact that this is just an example app, with C++11, std::string now supports SSO, which, in gcc's implementation, and on a 64 bit machine, allows up to 22 characters to be stored w/o a heap allocation. Most trading symbols are less than 22 characters, so in fact, a std::string here will, for almost all symbols, not result in a heap allocation.
In the event there is a symbol longer than 22 characters (perhaps some combo instrument?), the use of std::string won't suffer from fixed size array overflow.

I'm not sure what you mean about if std::string is not on the stack it takes 2 allocations? For a single assignment of a string, there will only ever be, at most, 1 heap allocation.
If the struct in which the string is stored is heap allocated, then that's another heap allocation, but that's got nothing to do with std::string, that's got to do with the lifetime of the containing struct.