diff --git a/src/streams.cpp b/src/streams.cpp index baa5ad7abed..cd496ee2be4 100644 --- a/src/streams.cpp +++ b/src/streams.cpp @@ -2,6 +2,7 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or https://opensource.org/license/mit/. +#include #include #include #include @@ -110,3 +111,8 @@ bool AutoFile::Truncate(unsigned size) { return ::TruncateFile(m_file, size); } + +size_t DataStream::GetMemoryUsage() const noexcept +{ + return sizeof(*this) + memusage::DynamicUsage(vch); +} diff --git a/src/streams.h b/src/streams.h index e9f3562c6ce..64dbfbff145 100644 --- a/src/streams.h +++ b/src/streams.h @@ -277,6 +277,9 @@ public: { util::Xor(MakeWritableByteSpan(*this), MakeByteSpan(key)); } + + /** Compute total memory usage of this object (own memory + any dynamic memory). */ + size_t GetMemoryUsage() const noexcept; }; template