From 608c444694735e3be9195e5ad418ac8c43d00733 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Mon, 6 Sep 2021 00:31:59 +0300 Subject: [PATCH] Update Buffer.hpp --- module/Core/Buffer.hpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/module/Core/Buffer.hpp b/module/Core/Buffer.hpp index 1435d71c..b241797a 100644 --- a/module/Core/Buffer.hpp +++ b/module/Core/Buffer.hpp @@ -148,6 +148,7 @@ public: : m_Ptr(o.m_Ptr), m_Cap(o.m_Cap), m_Cur(o.m_Cur) { o.m_Ptr = nullptr; + o.m_Cap = o.m_Cur = 0; } /* -------------------------------------------------------------------------------------------- @@ -175,6 +176,7 @@ public: m_Cap = o.m_Cap; m_Cur = o.m_Cur; o.m_Ptr = nullptr; + o.m_Cap = o.m_Cur = 0; } return *this; } @@ -856,6 +858,17 @@ public: m_Cur += Write(m_Cur, str, size); } + /* -------------------------------------------------------------------------------------------- + * Steal ownership of the internal memory buffer. Whoever gets hold of the buffer must invoke delete [] on it. + */ + SQMOD_NODISCARD Pointer Steal() + { + Pointer ptr = m_Ptr; + m_Ptr = nullptr; + m_Cap = m_Cur = 0; // Save this before calling this method + return ptr; + } + protected: /* --------------------------------------------------------------------------------------------