Skip to content

Commit 047b5e2

Browse files
committed
streams: add DataStream::GetMemoryUsage
1 parent c3a6722 commit 047b5e2

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/streams.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or https://opensource.org/license/mit/.
44

5+
#include <memusage.h>
56
#include <span.h>
67
#include <streams.h>
78
#include <util/fs_helpers.h>
@@ -110,3 +111,8 @@ bool AutoFile::Truncate(unsigned size)
110111
{
111112
return ::TruncateFile(m_file, size);
112113
}
114+
115+
size_t DataStream::GetMemoryUsage() const noexcept
116+
{
117+
return sizeof(*this) + memusage::DynamicUsage(vch);
118+
}

src/streams.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ class DataStream
277277
{
278278
util::Xor(MakeWritableByteSpan(*this), MakeByteSpan(key));
279279
}
280+
281+
/** Compute total memory usage of this object (own memory + any dynamic memory). */
282+
size_t GetMemoryUsage() const noexcept;
280283
};
281284

282285
template <typename IStream>

0 commit comments

Comments
 (0)