Skip to content

Commit

Permalink
utils: Use BOOST_CLASS_IMPLEMENTATION on Array/Vector
Browse files Browse the repository at this point in the history
Change the Boost serialization object class info to elide two
short ints (version for Utils::detail::Storage and Utils::Array),
thus reducing the serialization buffer size by 25% for Vector3i
(from 16 to 12 bytes) and by 14% for Vector3d (from 28 to 24 bytes).
  • Loading branch information
jngrad committed Jan 3, 2022
1 parent afba12e commit 803841e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/utils/include/utils/Array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "device_qualifier.hpp"
#include "get.hpp"
#include "serialization/array.hpp"

#include <boost/serialization/access.hpp>
#include <boost/serialization/array_wrapper.hpp>
Expand Down Expand Up @@ -210,4 +211,8 @@ auto get(Array<T, N> const &a) -> std::enable_if_t<(I < N), const T &> {
}

} // namespace Utils

UTILS_ARRAY_BOOST_CLASS(Utils::detail::Storage, N, object_serializable)
UTILS_ARRAY_BOOST_CLASS(Utils::Array, N, object_serializable)

#endif
3 changes: 3 additions & 0 deletions src/utils/include/utils/Vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,4 +500,7 @@ template <typename T> struct deduce_vec<Utils::Vector<T, 3>, 3> {

} // namespace qvm
} // namespace boost

UTILS_ARRAY_BOOST_CLASS(Utils::Vector, N, object_serializable)

#endif
52 changes: 52 additions & 0 deletions src/utils/include/utils/serialization/array.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (C) 2021 The ESPResSo project
*
* This file is part of ESPResSo.
*
* ESPResSo is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ESPResSo is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UTILS_SERIALIZATION_ARRAY_HPP
#define UTILS_SERIALIZATION_ARRAY_HPP

#include <boost/mpl/int.hpp>
#include <boost/mpl/integral_c_tag.hpp>
#include <boost/serialization/level.hpp>

#include <cstddef>

#define UTILS_ARRAY_TEMPLATE_T_N template <typename T, std::size_t N>
#define UTILS_ARRAY_TEMPLATE_T_0 template <typename T>
#define UTILS_ARRAY_CONTAINER_T_N(Container) Container<T, N>
#define UTILS_ARRAY_CONTAINER_T_0(Container) Container<T>

/**
* @brief Redefinition of @c BOOST_CLASS_IMPLEMENTATION for array types.
* @tparam Container Template template type of the array
* @tparam N N if @p Container uses std::size_t N, else 0
* @tparam ImplementationLevel Serialization implementation level
*/
#define UTILS_ARRAY_BOOST_CLASS(Container, N, ImplementationLevel) \
namespace boost { \
namespace serialization { \
UTILS_ARRAY_TEMPLATE_T_##N struct implementation_level_impl< \
const UTILS_ARRAY_CONTAINER_T_##N(Container)> { \
typedef mpl::integral_c_tag tag; \
typedef mpl::int_<ImplementationLevel> type; \
BOOST_STATIC_CONSTANT(int, \
value = implementation_level_impl::type::value); \
}; \
} /* namespace serialization */ \
} /* namespace boost */

#endif

0 comments on commit 803841e

Please sign in to comment.