> Yet other cases are libraries that are designed to be bundled
> because they do not attempt to provide a stable API or sufficient
> run-time configuration of options (this one happens a lot more
> often than I'd like).
This sounds like a good reason to use a different library to provide the needed functionality.
> And yet other cases are small technical integration needs
> (inlining w/ LTO a matrix math library, for instance, can have
> such a huge impact on performance that using it as a shared
> library is downright stupid).
In that case, shouldn't the distributions provide a statically linked version of the library that you can depend on? It seems like there's no technical barrier to doing this.
Posted Apr 8, 2012 11:13 UTC (Sun) by epa (subscriber, #39769)
[Link]
By 'inlining' the matrix library I think the other poster meant doing type specialization at compile type, as C++ does, so building a specialized Matrix<Foo> type for your application's type Foo. If you included the library at link time instead, whether by static linking or dynamic linking, it would have to be a Matrix<Foo *> or Matrix<void *> instead, since the Matrix library wasn't built with knowledge of the Foo type. The extra pointer dereferences can slow things down a lot.
Bundled == old
Posted Apr 8, 2012 19:47 UTC (Sun) by cmccabe (guest, #60281)
[Link]
The Matrix library doesn't have to have knowledge of type Foo. Matrix<Foo> will be instantiated when the application is built. All of that works fine-- yes, even with dynamically linked libraries. Let's not forget, libstdc++ is a dynamically linked library itself, and it's stuffed full of templates.
The problems start when you try to deal with versioning. Basically, templates make creating any kind of backwards-compatible API much harder. This is one reason why the libstdc++ std::string still uses a reference-counted implementation, despite the fact that it's known to be slow on modern multi-threaded machines. Changing std::string (otherwise known as std::basic_string <char, traits, alloc>) would just break too many things.
Posted Apr 9, 2012 14:02 UTC (Mon) by HelloWorld (guest, #56129)
[Link]
> The Matrix library doesn't have to have knowledge of type Foo. Matrix<Foo> will be instantiated when the application is built. All of that works fine-- yes, even with dynamically linked libraries. Let's not forget, libstdc++ is a dynamically linked library itself, and it's stuffed full of templates.
The template stuff isn't linked dynamically (except maybe for a few explicitly instanciated templates). In fact, many template libraries, such as boost spirit, boost xpressive or Eigen consist solely of headers.
Bundled == old
Posted Apr 9, 2012 16:41 UTC (Mon) by cmccabe (guest, #60281)
[Link]
Templates may or may not have external linkage. It depends on how they were instantiated. It's perfectly possible, for example, for the shared library to use explicit instantiation to create Matrix<Foo>, Matrix<Bar>, and Matrix<Baz>. On the other hand, since a lot of the benefit of this kind of templating comes from inlining, this would probably not be the style used in a matrix multiplication library.
It's also possible for templates declared in a header file and instantiated in library client code (inline) to call functions from a shared library. This is where most of the version skew problems come from, since when the library client is linked against another version of the shared library, he will not update his inlined templates, but will be using different versions of those functions.
Bundled == old
Posted Apr 10, 2012 9:19 UTC (Tue) by epa (subscriber, #39769)
[Link]
I'm not sure I understand you rightly, but I always thought that it was impossible for a library to provide Matrix<Foo> unless the author of the library already knew about the Foo type. If Foo is a type specific to your application, it's not going to be something your matrix library knows about. Is that no longer the case with today's C++ toolchains?
Bundled == old
Posted Apr 10, 2012 15:22 UTC (Tue) by cmccabe (guest, #60281)
[Link]
No, you can't instantiate Matrix<Foo> without knowing about type Foo. I'm just saying that there are a lot of templates out there that aren't inlined.
My biggest point, if I have one, is that mixing the inlined and non-inlined stuff is what creates the versioning problems.