Changes between Version 23 and Version 24 of BestPracticeHandbook


Ignore:
Timestamp:
May 14, 2015, 11:41:18 PM (7 years ago)
Author:
Niall Douglas
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • BestPracticeHandbook

    v23 v24  
    951951These are for a single core 3.9Ghz i7-3770K computer. I think the results speak for themselves, and note that AFIO is only 8k lines with not much metaprogramming.
    952952
    953 The approaches for improving build times for your library users are generally as follows:
    954 
    955 TODO
     953The approaches for improving build times for your library users are generally as follows, and in order of effect:
     954
     955 1. Offer a non-header only build configuration:: Here is how many Boost libraries offer both header only and non-header only build configurations by using something like this in their config.hpp:
     956
     957 {{{#!c++
     958// If we are compiling not header only
     959#if (defined(BOOST_AFIO_DYN_LINK) || defined(BOOST_ALL_DYN_LINK)) && !defined(BOOST_AFIO_STATIC_LINK)
     960
     961# if defined(BOOST_AFIO_SOURCE)                // If we are compiling the library binary
     962#  undef BOOST_AFIO_HEADERS_ONLY
     963#  define BOOST_AFIO_DECL BOOST_SYMBOL_EXPORT    // Mark public symbols as exported from the library binary
     964#  define BOOST_AFIO_BUILD_DLL                   // Tell code we are building a DLL or shared object
     965# else
     966#  define BOOST_AFIO_DECL BOOST_SYMBOL_IMPORT    // If not compiling the library binary, mark public symbols are imported from the library binary
     967# endif
     968#else                                          // If we are compiling header only
     969# define BOOST_AFIO_DECL                         // Do no markup of public symbols
     970#endif // building a shared library
     971
     972
     973// Configure Boost auto link to get the compiler to auto link your library binary
     974#if !defined(BOOST_AFIO_SOURCE) && !defined(BOOST_ALL_NO_LIB) && \
     975    !defined(BOOST_AFIO_NO_LIB) && !AFIO_STANDALONE && !BOOST_AFIO_HEADERS_ONLY
     976
     977#define BOOST_LIB_NAME boost_afio
     978
     979// tell the auto-link code to select a dll when required:
     980#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_AFIO_DYN_LINK)
     981#define BOOST_DYN_LINK
     982#endif
     983
     984#include <boost/config/auto_link.hpp>
     985
     986#endif  // auto-linking disabled
     987
     988
     989#if BOOST_AFIO_HEADERS_ONLY == 1                              // If AFIO is headers only
     990# define BOOST_AFIO_HEADERS_ONLY_FUNC_SPEC inline               // Mark all functions as inline
     991# define BOOST_AFIO_HEADERS_ONLY_MEMFUNC_SPEC inline            // Mark all member functions as inline
     992# define BOOST_AFIO_HEADERS_ONLY_VIRTUAL_SPEC inline virtual    // Mark all virtual member functions as inline virtual
     993// GCC gets upset if inline virtual functions aren't defined
     994# ifdef BOOST_GCC
     995#  define BOOST_AFIO_HEADERS_ONLY_VIRTUAL_UNDEFINED_SPEC { BOOST_AFIO_THROW_FATAL(std::runtime_error("Attempt to call pure virtual member function")); abort(); }
     996# else
     997#  define BOOST_AFIO_HEADERS_ONLY_VIRTUAL_UNDEFINED_SPEC =0;
     998# endif
     999#else                                                         // If AFIO is not headers only
     1000# define BOOST_AFIO_HEADERS_ONLY_FUNC_SPEC extern BOOST_AFIO_DECL  // Mark all functions as extern dllimport/dllexport
     1001# define BOOST_AFIO_HEADERS_ONLY_MEMFUNC_SPEC                      // Mark all member functions with nothing
     1002# define BOOST_AFIO_HEADERS_ONLY_VIRTUAL_SPEC virtual              // Mark all virtual member functions as virtual (no inline)
     1003# define BOOST_AFIO_HEADERS_ONLY_VIRTUAL_UNDEFINED_SPEC =0;        // Mark all pure virtual member functions with nothing special
     1004#endif
     1005 }}}
     1006
     1007 This looks a bit complicated, but isn't really. Generally you will mark up those classes and structs you implement in a .ipp file (this being the file implementing the APIs declared in the header) with `BOOST_AFIO_DECL`, functions with `BOOST_AFIO_HEADERS_ONLY_FUNC_SPEC`, all out-of-class member functions (i.e. those not implemented inside the class or struct declaration) with `BOOST_AFIO_HEADERS_ONLY_MEMFUNC_SPEC`, all virtual member functions with `BOOST_AFIO_HEADERS_ONLY_VIRTUAL_SPEC` and append to all unimplemented virtual member functions  `BOOST_AFIO_HEADERS_ONLY_VIRTUAL_UNDEFINED_SPEC`. This inserts the correct markup to generate both optimal header only and optimal non header only outcomes.
     1008
     1009 2. Precompiled headers:: todo
     1010
     1011 3. extern template pre-instantiated copies of your templates with their most common template parameters into a separate static library:: todo
     1012
    9561013
    9571014== 16. COUPLING: Consider allowing your library users to dependency inject your dependencies on other libraries ==