From bdc4a09356a61805958aa80d03691e5bbfe80565 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Sat, 23 Jan 2021 06:48:39 +1000 Subject: [PATCH] tools/analyse: use a deque to avoid expensive reallocations We can amass a fair amount of allocated memory on some operations, so a vector resize can exceed the available memory of a system on some operations. --- tools/analyse.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tools/analyse.cpp b/tools/analyse.cpp index 7ddfdfa..a83a660 100644 --- a/tools/analyse.cpp +++ b/tools/analyse.cpp @@ -24,6 +24,7 @@ #include #include #include +#include /////////////////////////////////////////////////////////////////////////////// @@ -64,7 +65,7 @@ static bool region_equal ( /////////////////////////////////////////////////////////////////////////////// static void find_path_chunks ( - std::vector &res, + std::deque &res, std::filesystem::path const &src, emory::chunk::params const &p ); @@ -75,7 +76,7 @@ static void find_path_chunks ( static void find_regular_chunks ( - std::vector &res, + std::deque &res, std::filesystem::path const &src, emory::chunk::params const &p ) { @@ -96,7 +97,7 @@ find_regular_chunks ( static void find_directory_chunks ( - std::vector &res, + std::deque &res, std::filesystem::path const &src, emory::chunk::params const &p ) { @@ -111,7 +112,7 @@ find_directory_chunks ( /// Scan chunks from a given path by dispatching to `find_foo_chunks` style /// functions depending on the file type. static void find_path_chunks ( - std::vector &res, + std::deque &res, std::filesystem::path const &src, emory::chunk::params const &p ) { @@ -139,12 +140,12 @@ static void find_path_chunks ( ///---------------------------------------------------------------------------- -/// Find all regions in a path and return a vector of the regions. +/// Find all regions in a path and return a container of the regions. static -std::vector +std::deque find_chunks (std::filesystem::path const &src, emory::chunk::params const &p) { - std::vector res; + std::deque res; find_path_chunks (res, src, p); return res; } @@ -194,7 +195,7 @@ int main (int argc, char const **argv) // Find all the chunks and prepare them for output std::cout << "processing\n"; - std::vector src = find_chunks (argv[ARGS_INPUT], p); + auto src = find_chunks (argv[ARGS_INPUT], p); fmt::print ("analysing {} chunks\n", src.size ()); std::sort (src.begin (), src.end (), region_less);