[vtkusers] vtkStdString vs vtkstd::string

Brad King brad.king at kitware.com
Fri Jan 15 09:57:02 EST 2010


Jeff Baumes wrote:
> On Wed, Jan 13, 2010 at 7:15 PM, David Doria <daviddoria+vtk at gmail.com> wrote:
>> The doc for vtkStdString says:
>>
>> Wrapper around vtkstd::string to keep symbols short.
>> vtkStdString derives from vtkstd::string to provide shorter symbol
>> names than basic_string<...> in namespace std given by the standard
>> STL string.
>>
>> But I guess I don't understand what that means. When should one use
>> vtkStdString vs vtkstd::string?
> 
> I don't know the answer to your question

Use vtkStdString as a template argument to STL class templates and
nothing else.  It keeps error messages shorter.  Also, for MSVC it
helps produce shorter underlying symbol names, reducing the chance
of conflict since the compiler's ABI has a limited symbol length
(255 or so IIRC).

The documentation David quotes is trying to explain the following:

$ cat foo.cxx
#include <string>
#include <map>
void f(std::string) {}
void g(std::map<std::string, std::string>) {}
$ g++ -c foo.cxx
$ nm foo.o | c++filt
0000000000000000 T f(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)
000000000000000a T g(std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >,
std::allocator<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >)

$ cat bar.cxx
#include <string>
#include <map>
class mystring: public std::string {};
void f(mystring) {}
void g(std::map<mystring, mystring>) {}
$ g++ -c bar.cxx
$ nm bar.o | c++filt
0000000000000000 T f(mystring)
000000000000000a T g(std::map<mystring, mystring, std::less<mystring>, std::allocator<std::pair<mystring const, mystring> > >)


The above is an explanation of the motivation behind vtkStdString, not
an argument for or against it.  However, these days the motivation may
be out-dated.  Continuing from the above example:

$ nm foo.o
0000000000000000 T _Z1fSs
000000000000000a T _Z1gSt3mapISsSsSt4lessISsESaISt4pairIKSsSsEEE

$ nm bar.o
0000000000000000 T _Z1f8mystring
000000000000000a T _Z1gSt3mapI8mystringS0_St4lessIS0_ESaISt4pairIKS0_S0_EEE

So at least for g++ 4.3 on Linux the std::string mangling is shorter
than the mystring mangling anyway!

-Brad



More information about the vtkusers mailing list