From 047b5e2af1f03549d85926aa02fed0dfa00d449f Mon Sep 17 00:00:00 2001 From: laanwj <126646+laanwj@users.noreply.github.com> Date: Sun, 27 Oct 2024 09:04:54 +0100 Subject: [PATCH] streams: add DataStream::GetMemoryUsage --- src/streams.cpp | 6 ++++++ src/streams.h | 3 +++ 2 files changed, 9 insertions(+) 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