Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should you use an STL other than the one that comes with your compiler?

Tags:

c++

stl

I was curious about STL implementations outside of what's packaged with gcc or Visual Studio, so a quick Google search turned up a few results, such as:

  • Apache stdcxx
  • uSTL
  • rdeSTL

Under what circumstances should one use an alternative standard template library?

For instance, Apache's page has a list including items such as "full conformance to the C++ standard" and "optimized for fast compiles and extremely small executable file sizes". If it's so good, why wouldn't it replace libstdc++?


For the sake of completeness, here are some of the other STL implementations:
  • STLPort
  • STXXL (which is sort of special purpose, meant for large data sets that won't fit in memory)
  • Dinkumware (commercial)
  • SGI STL
  • libstdc++ (GCC's implementation)
like image 943
Mark Rushakoff Avatar asked Nov 10 '09 17:11

Mark Rushakoff


People also ask

What is the use of STL in C++?

C++ STL (standard template library) is a software library for the C++ language that provides a collection of templates representing containers, iterators, algorithms, and function objects.

How is STL different from C++ Standard Library?

The Standard Template Library (STL) is a software library for the C++ programming language that influenced many parts of the C++ Standard Library. It provides four components called algorithms, containers, functions, and iterators.


1 Answers

I never had to use an STL version other than the one packed with the compiler. But here are some points that come into my mind.

  • Thread-safety: The STL from apache provides a compile switch to turn on/off some thread-safety features.
  • Localization: Again the STL from apache comes with nice support for many different locales.
  • Data structures: You might need a basic_string implementation that is based on COW (copy-on-write) and the STL version that came with your compiler doesn't offer that.
  • Non-standard extensions: Particular features you like from some other STL implementations. For example, hash_map (and related) versions from Dinkumware (which ships with Visual Studio) have a significantly different design from hash_map (and related) from STLPort.
  • Binary issues: Constraints in some environment (embedded software) due to code size. In such case, if you don't need the whole STL it could be interesting to use a reduced version.
  • Performance: What if you discovered, after profiling, that the "other" STL implementation gives you significant better performance for a particular application. (With so many details concerning algorithms and data structures this could actually be possible.)
  • Debug mode: Some STL implementation provide nice features for debugging. For instance, checking ranges of iterators.
like image 130
Leandro T. C. Melo Avatar answered Sep 21 '22 20:09

Leandro T. C. Melo