On Sat, Jan 19, 2013 at 8:33 PM, Michael Spencer <bigcheesegs at gmail.com> wrote:> There isn't much use of std::string in LLVM because it's simply not > needed. There's very little string manipulation, so StringRef is often > a much better choice. When there is a need for string manipulation, > the strings are generally very short, so SmallString is better.Although SmallString is actually pretty inefficient, since it keeps the string data separate from the "vector" header. I believe libc++'s std::string actually reuses the pointers in the "vector header" as the storage for the "small" size, and so in that case std::string is effectively a very memory efficient SmallString with storage of roughly 3 pointers' worth of chars. -- Sean Silva
On 1/19/2013 7:55 PM, Sean Silva wrote:> > Although SmallString is actually pretty inefficient, since it keeps > the string data separate from the "vector" header. I believe libc++'s > std::string actually reuses the pointers in the "vector header" as the > storage for the "small" size, and so in that case std::string is > effectively a very memory efficient SmallString with storage of > roughly 3 pointers' worth of chars.Why do we actually have all the local versions of containers that already exist as a part of the C++ standard (such as SmallVector, DenseMap, et al.)? -Krzysztof -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
On Jan 19, 2013, at 6:00 PM, Krzysztof Parzyszek <kparzysz at codeaurora.org> wrote:> On 1/19/2013 7:55 PM, Sean Silva wrote: >> >> Although SmallString is actually pretty inefficient, since it keeps >> the string data separate from the "vector" header. I believe libc++'s >> std::string actually reuses the pointers in the "vector header" as the >> storage for the "small" size, and so in that case std::string is >> effectively a very memory efficient SmallString with storage of >> roughly 3 pointers' worth of chars. > > Why do we actually have all the local versions of containers that already exist as a part of the C++ standard (such as SmallVector, DenseMap, et al.)?See: http://llvm.org/docs/ProgrammersManual.html#picking-the-right-data-structure-for-a-task -Chris
On Sat, Jan 19, 2013 at 6:00 PM, Krzysztof Parzyszek <kparzysz at codeaurora.org> wrote:> On 1/19/2013 7:55 PM, Sean Silva wrote: >> >> >> Although SmallString is actually pretty inefficient, since it keeps >> the string data separate from the "vector" header. I believe libc++'s >> std::string actually reuses the pointers in the "vector header" as the >> storage for the "small" size, and so in that case std::string is >> effectively a very memory efficient SmallString with storage of >> roughly 3 pointers' worth of chars. > > > Why do we actually have all the local versions of containers that already > exist as a part of the C++ standard (such as SmallVector, DenseMap, et al.)?Short answer: ours are better. Longer answer: ours are better for particular situations. (you'll notice, for example, that DenseMap has different iterator invalidation semantics & requires a tombstone value - by paying that cost the container can be a bit faster and/or more memory efficient) For details: http://llvm.org/docs/ProgrammersManual.html