From f2a9b344788eac36b860b60f9d29eac9bab165bb Mon Sep 17 00:00:00 2001 From: Kris Jusiak Date: Mon, 2 Oct 2023 22:37:29 -0500 Subject: [PATCH] :fire: BOOST_SML_CREATE_DEFAULT_CONSTRUCTIBLE_DEPS to optimize memory consumption 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. --- example/data.cpp | 1 + include/boost/sml.hpp | 2 ++ test/ft/deep_sm.cpp | 1 + test/ft/dependencies.cpp | 3 ++- 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/example/data.cpp b/example/data.cpp index bcc42292..5ec61948 100644 --- a/example/data.cpp +++ b/example/data.cpp @@ -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 #include #include diff --git a/include/boost/sml.hpp b/include/boost/sml.hpp index fcf6a88c..fb57d81f 100644 --- a/include/boost/sml.hpp +++ b/include/boost/sml.hpp @@ -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 struct pool_type_impl::value && aux::is_constructible::value>> : pool_type_base { @@ -374,6 +375,7 @@ struct pool_type_impl::value && a T value_{}; T &value; }; +#endif template struct pool_type : pool_type_impl { using pool_type_impl::pool_type_impl; diff --git a/test/ft/deep_sm.cpp b/test/ft/deep_sm.cpp index 57158eaa..a020ed60 100644 --- a/test/ft/deep_sm.cpp +++ b/test/ft/deep_sm.cpp @@ -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 namespace sml = boost::sml; diff --git a/test/ft/dependencies.cpp b/test/ft/dependencies.cpp index 6d76de9f..112f1670 100644 --- a/test/ft/dependencies.cpp +++ b/test/ft/dependencies.cpp @@ -5,8 +5,9 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // -#include +#define BOOST_SML_CREATE_DEFAULT_CONSTRUCTIBLE_DEPS #include +#include #include #include #include