std::strstr...trstreambuf(3)
π std::strstreambuf::~strstreambuf π
okay bestie, welcome to the <std::strstreambuf::~strstreambuf> page from the manual named C++ Standard Libary (that's the manual name, exactly β and the page identifier is std::strstr...trstreambuf(3)). We're talking about a destructor, and it is highkey deprecated-era lore β no cap. β¨
πΈ NAME πΈ
std::strstreambuf::~strstreambufβstd::strstreambuf::~strstreambuf(yes, the NAME section said it twice, and honestly? iconic.)
β¨ Synopsis β¨
virtual ~strstreambuf(); (deprecated in C++98)
(removed in C++26)
so yeah, the signature is virtual ~strstreambuf();, and it carries two big labels: deprecated in C++98 and removed in C++26. π
It destroys a std::strstreambuf object. If the object is managing a dynamically-allocated buffer (the buffer state is "allocated") and it is not frozen, then it deallocates the buffer using the deallocation function provided at construction β or delete[] if none was provided. That's the whole behavior, bestie. π
π Parameters π
- (none) β literally no parameters. Destructor stays unbothered. π
π¦ Notes π¦
This destructor is typically called by the destructor of std::strstream.
Ifstr()was called on a dynamic strstream andfreeze(false)was not called after that, this destructor leaks memory. π Memory leak warning, bestie: do not ignore. So if that's your situation, please remember thefreeze(false)afterstr()β leaking memory is not the move.
π Example π
// Run this code
#include <iostream>
#include <strstream>
void* my_alloc(size_t n)
{
std::cout << "my_alloc(" << n << ") called\n";
return new char[n];
}
void my_free(void* p)
{
std::cout << "my_free() called\n";
delete[] (char*)p;
}
int main()
{
{
std::strstreambuf buf(my_alloc, my_free);
std::ostream s(&buf);
s << 1.23 << std::ends;
std::cout << buf.str() << '\n';
buf.freeze(false);
} // destructor called here, buffer deallocated
{
std::strstreambuf buf(my_alloc, my_free);
std::ostream s(&buf);
s << 1.23 << std::ends;
std::cout << buf.str() << '\n';
// buf.freeze(false);
} // destructor called here, memory leak!
}
Output:
my_alloc(4096) called
1.23
my_free() called
my_alloc(4096) called
1.23
okay that's the whole page, bestie. from http://cppreference.com, version/date 2024.06.10, page std::strstr...trstreambuf(3) β go forth and freeze your buffers appropriately π«Άπ
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms