Boost logo

Boost :

Subject: [boost] [assert] [exception] Fast output binary file size growth
From: Antony Polukhin (antoshkka_at_[hidden])
Date: 2012-01-25 12:10:25


Greetings,

When BOOST_ENABLE_ASSERT_HANDLER is defined or BOOST_THROW_EXCEPTION
used, compiler generates a string with function name.

If a function is templated, compiler will generate a string for each
function template. That leads to a huge binary files.

Consider the following example:

#define BOOST_ENABLE_ASSERT_HANDLER

#include <boost/assert.hpp>

template <class MplVectorT>

void do_something(bool v) {

    BOOST_ASSERT(v);

}

void do_something<boost::mpl::vector<int, double>>(v);

void do_something<boost::mpl::vector<int, int>>(v);

This two functions will generate strings like "void
do_something<MplVectorT>(bool v) [with MplVectorT =
boost::mpl::vector<int, double> ]" and

"void do_something<MplVectorT>(bool v) [with MplVectorT =
boost::mpl::vector<int, int> ]".

When there is more mataprogramming, one such string can have a size of
a few kilobytes. In one of my binaries,

such strings take more than 50 megabytes of binary size (total size of
binary is 70 megabytes).

I`ve got a patch and documentation update for Boost.Assert and
Boost.Exception, that allow to disable construction of such strings or
to use different macro for current function name (for example macro
that prints ONLY function name).

Is there interest in this feature/patches?

Best regards,

Antony Polukhin


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk