Skip to content

Commit

Permalink
streams: add DataStream::GetMemoryUsage
Browse files Browse the repository at this point in the history
  • Loading branch information
laanwj committed Nov 4, 2024
1 parent c3a6722 commit 047b5e2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/streams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or https://opensource.org/license/mit/.

#include <memusage.h>
#include <span.h>
#include <streams.h>
#include <util/fs_helpers.h>
Expand Down Expand Up @@ -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);
}
3 changes: 3 additions & 0 deletions src/streams.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ class DataStream
{
util::Xor(MakeWritableByteSpan(*this), MakeByteSpan(key));
}

/** Compute total memory usage of this object (own memory + any dynamic memory). */
size_t GetMemoryUsage() const noexcept;
};

template <typename IStream>
Expand Down

0 comments on commit 047b5e2

Please sign in to comment.