Skip to content

Commit

Permalink
On MSVC, std::deque degenerates to a list of pointers, which defeats
Browse files Browse the repository at this point in the history
its purpose of reducing allocator load and memory fragmentation.
microsoft/STL#147 (comment)
Slic3r::deque<> compiles to boost::container::deque<> on Windows,
to std::deque<> on other systems.
SeamPlacer newly uses Slic3r::deque<>.
  • Loading branch information
bubnikv authored and Godrak committed Apr 25, 2022
1 parent adb4672 commit 8c2e6ab
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/libslic3r/GCode/SeamPlacer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <memory>
#include <atomic>

#include "libslic3r/libslic3r.h"
#include "libslic3r/ExtrusionEntity.hpp"
#include "libslic3r/Polygon.hpp"
#include "libslic3r/PrintConfig.hpp"
Expand Down Expand Up @@ -93,7 +94,7 @@ struct PrintObjectSeamData

struct LayerSeams
{
std::deque<SeamPlacerImpl::Perimeter> perimeters;
Slic3r::deque<SeamPlacerImpl::Perimeter> perimeters;
std::vector<SeamPlacerImpl::SeamCandidate> points;
std::unique_ptr<SeamCandidatesTree> points_tree;
};
Expand Down
17 changes: 17 additions & 0 deletions src/libslic3r/libslic3r.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
#include <cmath>
#include <type_traits>

#ifdef _WIN32
// On MSVC, std::deque degenerates to a list of pointers, which defeats its purpose of reducing allocator load and memory fragmentation.
// https://github.com/microsoft/STL/issues/147#issuecomment-1090148740
// Thus it is recommended to use boost::container::deque instead.
#include <boost/container/deque.hpp>
#endif // _WIN32

#include "Technologies.hpp"
#include "Semver.hpp"

Expand Down Expand Up @@ -73,6 +80,16 @@ namespace Slic3r {

extern Semver SEMVER;

// On MSVC, std::deque degenerates to a list of pointers, which defeats its purpose of reducing allocator load and memory fragmentation.
template<class T, class Allocator = std::allocator<T>>
using deque =
#ifdef _WIN32
// Use boost implementation, which allocates blocks of 512 bytes instead of blocks of 8 bytes.
boost::container::deque<T, Allocator>;
#else // _WIN32
std::deque<T, Allocator>;
#endif // _WIN32

template<typename T, typename Q>
inline T unscale(Q v) { return T(v) * T(SCALING_FACTOR); }

Expand Down
6 changes: 6 additions & 0 deletions src/libslic3r/pchheader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@
#include <boost/config.hpp>
#include <boost/config/warning_disable.hpp>
#include <boost/container/small_vector.hpp>
#ifdef _WIN32
// On MSVC, std::deque degenerates to a list of pointers, which defeats its purpose of reducing allocator load and memory fragmentation.
// https://github.com/microsoft/STL/issues/147#issuecomment-1090148740
// Thus it is recommended to use boost::container::deque instead.
#include <boost/container/deque.hpp>
#endif // _WIN32
#include <boost/date_time/local_time/local_time.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/filesystem.hpp>
Expand Down

0 comments on commit 8c2e6ab

Please sign in to comment.