[vtkusers] vtkStdString vs vtkstd::string

Bill Lorensen bill.lorensen at gmail.com
Fri Jan 15 11:02:55 EST 2010


My one test example change yesterday compiled cleanly last night. I'll
start fixing the examples to use std::.

Bill

On Fri, Jan 15, 2010 at 9:57 AM, Brad King <brad.king at kitware.com> wrote:
> 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
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>



More information about the vtkusers mailing list