Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ interface design around shared library boundaries
    text
    copied!<p>Suppose I have two projects. One is an application and the other is a shared library that contains common, reusable code that could be used by more than just this application.</p> <p>My application uses STL, and my shared library also uses STL. The first problem here is that my shared library is using STL. If I ever build a newer version of STL into my application but I do not rebuild my shared library because it is not necessary, then we will have compatibility issues right away.</p> <p>My first thought to solve this issue is to not use STL at all in the interface to the shared library classes. Suppose we have a function in my library that takes a string and does something with it. I would make the function prototype look like:</p> <pre><code>void DoStuffWithStrings( char const* str ); </code></pre> <p>instead of:</p> <pre><code>void DoStuffWithStrings( std::string const&amp; str ); </code></pre> <p>For strings this will probably be OK between different versions of STL, but the downside is that we are going from <code>std::string</code>, to <code>char*</code>, and back to <code>std::string</code>, which seems like it causes performance issues.</p> <p>Is the boxing/unboxing of raw types to their STL counterparts recommended? This becomes even worse when we try to do this to a <code>std::list</code>, since there really is no "raw type" I am aware of that we could easily pass it as without doing some sort of O(n) or similar operation.</p> <p>What designs work best in this scenario? What are the pros/cons of each?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload