From 2768796708eb95e4e1187f14a194ad582b3c7d08 Mon Sep 17 00:00:00 2001 From: Norbert Podhorszki Date: Wed, 9 Dec 2020 09:51:05 -0500 Subject: [PATCH] settle on using std::fill() --- .../toolkit/format/buffer/heap/BufferSTL.cpp | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/source/adios2/toolkit/format/buffer/heap/BufferSTL.cpp b/source/adios2/toolkit/format/buffer/heap/BufferSTL.cpp index c7466ffd01..3d862e9469 100644 --- a/source/adios2/toolkit/format/buffer/heap/BufferSTL.cpp +++ b/source/adios2/toolkit/format/buffer/heap/BufferSTL.cpp @@ -53,27 +53,25 @@ void BufferSTL::Reset(const bool resetAbsolutePosition, } if (zeroInitialize) { - // m_Buffer.assign(m_Buffer.size(), '\0'); - // memset(static_cast(&m_Buffer[0]), 0, m_Buffer.size()); std::fill(m_Buffer.begin(), m_Buffer.end(), 0); } - /* else + else + { + // just zero out the first and last 1kb + const size_t bufsize = m_Buffer.size(); + size_t s = (bufsize < 1024 ? bufsize : 1024); + std::fill_n(m_Buffer.begin(), s, 0); + if (bufsize > 1024) { - // just zero out the first and last 1kb - const size_t bufsize = m_Buffer.size(); - size_t s = (bufsize < 1024 ? bufsize : 1024); - memset(static_cast(&m_Buffer[0]), 0, s); - if (bufsize > 1024) + size_t pos = bufsize - 1024; + if (pos < 1024) { - size_t pos = bufsize - 1024; - if (pos < 1024) - { - pos = 1024; - } - s = bufsize - pos; - memset(static_cast(&m_Buffer[pos]), 0, s); + pos = 1024; } - }*/ + s = bufsize - pos; + std::fill_n(next(m_Buffer.begin(), pos), s, 0); + } + } } size_t BufferSTL::GetAvailableSize() const