From 8c2e6aba79eeb6b042bbbfe225b6b82c8eea166f Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Mon, 11 Apr 2022 15:18:12 +0200 Subject: [PATCH] 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 Slic3r::deque<> compiles to boost::container::deque<> on Windows, to std::deque<> on other systems. SeamPlacer newly uses Slic3r::deque<>. --- src/libslic3r/GCode/SeamPlacer.hpp | 3 ++- src/libslic3r/libslic3r.h | 17 +++++++++++++++++ src/libslic3r/pchheader.hpp | 6 ++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/libslic3r/GCode/SeamPlacer.hpp b/src/libslic3r/GCode/SeamPlacer.hpp index 15dcd702a..a918ff1b3 100644 --- a/src/libslic3r/GCode/SeamPlacer.hpp +++ b/src/libslic3r/GCode/SeamPlacer.hpp @@ -6,6 +6,7 @@ #include #include +#include "libslic3r/libslic3r.h" #include "libslic3r/ExtrusionEntity.hpp" #include "libslic3r/Polygon.hpp" #include "libslic3r/PrintConfig.hpp" @@ -93,7 +94,7 @@ struct PrintObjectSeamData struct LayerSeams { - std::deque perimeters; + Slic3r::deque perimeters; std::vector points; std::unique_ptr points_tree; }; diff --git a/src/libslic3r/libslic3r.h b/src/libslic3r/libslic3r.h index 5e0fb67b3..2131a9233 100644 --- a/src/libslic3r/libslic3r.h +++ b/src/libslic3r/libslic3r.h @@ -23,6 +23,13 @@ #include #include +#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 +#endif // _WIN32 + #include "Technologies.hpp" #include "Semver.hpp" @@ -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> +using deque = +#ifdef _WIN32 + // Use boost implementation, which allocates blocks of 512 bytes instead of blocks of 8 bytes. + boost::container::deque; +#else // _WIN32 + std::deque; +#endif // _WIN32 + template inline T unscale(Q v) { return T(v) * T(SCALING_FACTOR); } diff --git a/src/libslic3r/pchheader.hpp b/src/libslic3r/pchheader.hpp index e6591f574..aeb79e3d8 100644 --- a/src/libslic3r/pchheader.hpp +++ b/src/libslic3r/pchheader.hpp @@ -64,6 +64,12 @@ #include #include #include +#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 +#endif // _WIN32 #include #include #include