design_rationale.qbk 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. [/
  2. Copyright 2014 Renato Tegon Forti, Antony Polukhin
  3. Copyright 2015-2019 Antony Polukhin
  4. Distributed under the Boost Software License, Version 1.0.
  5. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. /]
  7. [section Design Rationale]
  8. [section ABI portability across compilers]
  9. During discussion of the library a lot of questions were about ABI stability and should the library
  10. take care about it. It was decided that making ABI stable could be a useful feature, but it will
  11. add a lot of overhead and make the library usage less simple. For those who do not require ABI
  12. stability across compilers such feature will be an overkill.
  13. It was decided to make this library more simple and low level, so that it could be used to make ABI
  14. stable plugins system for users that require it still not adding overhead for other users.
  15. [endsect]
  16. [section User's plugin API]
  17. There are some open C++ plugin systems. Most of them force user to have some predefined API. The
  18. problem is that all of those API differ.
  19. To be more usable Boost.DLL does not force API. It's up to user to design suitable API.
  20. [endsect]
  21. [section Performance and memory allocations]
  22. Some methods of the library use `boost::filesystem::path` or return `std::vector<std::string>`. This
  23. may look non optimal at first, but there is a reason to do so.
  24. `boost::filesystem::path` allows to transparently use Unicode strings with non-Unicode ones. Using it
  25. provides a more user-friendly interface for the library while the performance overhead is not noticeable
  26. because of a slow file system operations that occur in `boost::filesystem::path` accepting methods.
  27. `std::vector<std::string>` variables are returned by the `library_info` methods. Querying a library is a slow
  28. procedure anyway: it randomly reads parts of file from disc and executes algorithms that sometimes
  29. have linear complexity from sections or exported symbols count. Returning `std::vector<std::string>`
  30. simplifies implementation and does not require from user to keep an instance of `library_info` after
  31. query. Having not a very noticeable performance overhead in rarely called methods seems reasonable.
  32. Other methods are assumed to be hot paths and optimized as much as possible.
  33. [endsect]
  34. [section Self loading]
  35. There is a good big reason to make self loading via `shared_library(program_location())` instead of
  36. having some `shared_library::load_self()` member method. That reason is the requirement to have an ability to call
  37. `shared_library(this_line_location())` from any place, even from the main binary. We need that to link plugins
  38. into the binary and to create a transparent reference counting mechanism.
  39. Making multiple interfaces that do exactly the same things looks unreasonable to me, that's why
  40. `shared_library(program_location())` and `shared_library(this_line_location())` are used without
  41. `shared_library::load_self()`.
  42. [endsect]
  43. [section Aliases vs Mangling]
  44. Mangling depends on source code, for example `"boost::foo"` could be `foo` function or `foo` variable.
  45. Depending on that knowledge it must be mangled in different ways. More problems arise if `foo` is an
  46. overloaded function that accepts parameters: `"boost::foo(variant<int, short>)"`. In that case full
  47. name of parameter must be specified, which could be `boost::variant<int, short>` or `variant<int, short, void_, void_>`
  48. ...
  49. There was an idea to allow user to forward declare function and generate mangled name from it:
  50. ```
  51. namespace boost { void foo(variant<int, short>); }
  52. std::string mangled_name = boost::dll::magic_mangle(boost::foo);
  53. ```
  54. But that idea has epic failed because of linker problems and no reliable way to get mangled symbol name
  55. from compiler internals at compile time.
  56. That's why aliases were considered a lesser evil:
  57. ```
  58. BOOST_DLL_ALIAS(boost::foo, foo_variant) // in plugin
  59. "foo_variant" // in plugin importer
  60. ```
  61. [endsect]
  62. [endsect]