0

I have a question about use of the STL on the APIs of a C++ library. I've read a number of articles stating that such use is unsafe / bad practice due to memory allocation/deallocation issues across DLL boundaries, ABI stability, etc. However, I've noticed that a number of large C++ projects do use the STL on their APIs, notably Ogre3D and OpenSceneGraph. When building a large cross-platform (Windows, Mac, Linux) library, what are the best practices here? Is this really a problem, or not? Thanks!

Brian
  • 313
  • 2
  • 12
  • 6
    When you say "STL" do you mean the Standard Library? I think so, because you are using the C++14 tag. Then you might want to read [this](http://stackoverflow.com/questions/5205491/whats-this-stl-vs-c-standard-library-fight-all-about) and check whether you are using the right term. – Fabio says Reinstate Monica May 13 '16 at 14:59
  • Do you provide source, and is recompiled by each client, and does not communicate between clients? Is it dynamically linked? Do you permit caller to use different memory libraries? Do you provide a C++ shim over C-type interfaces or custom marshal helpers? – Yakk - Adam Nevraumont May 13 '16 at 14:59
  • 2
    Because the standard library [(not STL)](http://stackoverflow.com/questions/5205491/whats-this-stl-vs-c-standard-library-fight-all-about) uses templates, there's a *potential* for problems if the library is built with a different version from the application. – Mark Ransom May 13 '16 at 15:00
  • Can you post example code that is deemed unsafe in the articles/books you read? – R Sahu May 13 '16 at 15:04
  • 1
    Highly relevant: http://stackoverflow.com/q/22797418/103167 Is there anything you wanted to know that *isn't* covered there, or can this be marked as a duplicate? – Ben Voigt May 13 '16 at 15:06
  • By STL, yes, I mean the C++ Standard Library ( as you might find documented here http://en.cppreference.com/w/ ). I wasn't aware the Internet was so pedantic with the terminology. Ok, minor details aside... This would be a library that at least in the near-term is closed-source. We may be able to distribute source code at some point in the future. Library communicates with a remote server and is dynamically linked. Also, the above linked post doesn't mention anything about how/why some well known libraries use library containers on their APIs... – Brian May 13 '16 at 16:19
  • Also, a fairly old article: https://chadaustin.me/cppinterface.html Another one: https://www.murrayc.com/permalink/2007/03/12/abi-stability-of-c-libraries/ – Brian May 13 '16 at 16:25
  • I wonder how much of the whole debate is "purist" versus "realistic". I get it, but if you're basically reduced to only using C-style APIs, that's a pretty significant hinderance for use of the language... – Brian May 13 '16 at 16:32

0 Answers0