Skip to content

Commit

Permalink
🔥 BOOST_SML_CREATE_DEFAULT_CONSTRUCTIBLE_DEPS to optimize memory cons…
Browse files Browse the repository at this point in the history
…umption

Problem:
- If dependency is default constructible a copy is stored in sml which increases the memory consumption.

Solution:
- Make the feature optional by passing BOOST_SML_CREATE_DEFAULT_CONSTRUCTIBLE_DEPS. Disabled by default as SML is optimized for perf and memory.
  • Loading branch information
kris-jusiak committed Oct 3, 2023
1 parent 751b6f1 commit f2a9b34
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions example/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#define BOOST_SML_CREATE_DEFAULT_CONSTRUCTIBLE_DEPS
#include <boost/sml.hpp>
#include <cassert>
#include <iostream>
Expand Down
2 changes: 2 additions & 0 deletions include/boost/sml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ struct pool_type_impl : pool_type_base {
constexpr pool_type_impl(init i, TObject object) : value{i, object} {}
T value{};
};
#if defined(BOOST_SML_CREATE_DEFAULT_CONSTRUCTIBLE_DEPS)
template <class T>
struct pool_type_impl<T &, aux::enable_if_t<aux::is_constructible<T>::value && aux::is_constructible<T, const T &>::value>>
: pool_type_base {
Expand All @@ -374,6 +375,7 @@ struct pool_type_impl<T &, aux::enable_if_t<aux::is_constructible<T>::value && a
T value_{};
T &value;
};
#endif
template <class T>
struct pool_type : pool_type_impl<T> {
using pool_type_impl<T>::pool_type_impl;
Expand Down
1 change: 1 addition & 0 deletions test/ft/deep_sm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The goal of this file is only to compile a state machine with deeply nested
states that use on_entry events. The only requirement on this file is a
successful compilation without a ftemplate-depth error.
*/
#define BOOST_SML_CREATE_DEFAULT_CONSTRUCTIBLE_DEPS
#include <boost/sml.hpp>

namespace sml = boost::sml;
Expand Down
3 changes: 2 additions & 1 deletion test/ft/dependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <array>
#define BOOST_SML_CREATE_DEFAULT_CONSTRUCTIBLE_DEPS
#include <boost/sml.hpp>
#include <array>
#include <memory>
#include <string>
#include <type_traits>
Expand Down

0 comments on commit f2a9b34

Please sign in to comment.