diff --git a/dumux/io/container.hh b/dumux/io/container.hh index fd4a17e3af80568162323d4ea711d9809008b6e4..9d8d68a810ed175e2602066b2cb3536d34c21dc6 100644 --- a/dumux/io/container.hh +++ b/dumux/io/container.hh @@ -52,14 +52,16 @@ void writeContainerToFile(const Container& v, /*! * \brief Read a simple text file into a container * \param filename The filename to write to + * \param sizeEstimate an estimate on how many items are there to read into the container * \tparam Container The container type, requires begin(), end(), push_back() method * * usage: auto v = readFileToContainer>("myvector.txt"); */ template -Container readFileToContainer(const std::string& filename) +Container readFileToContainer(const std::string& filename, std::size_t sizeEstimate = 0) { Container v; + if (sizeEstimate > 0) v.reserve(sizeEstimate); // reserving memory can significantly speed up the reading std::ifstream infile(filename, std::ios::in); std::istream_iterator it(infile); std::copy(it, std::istream_iterator(), std::back_inserter(v));