GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::strstreambuf::~strstreambuf(3) C++ Standard Libary std::strstreambuf::~strstreambuf(3)

std::strstreambuf::~strstreambuf - std::strstreambuf::~strstreambuf


virtual ~strstreambuf();


Destroys a std::strstreambuf object. if the object is managing a
dynamically-allocated buffer (the buffer state is "allocated") and if the object is
not frozen, then deallocates the buffer using the deallocation function provided at
construction or delete[] if none was provided.


(none)


This destructor is typically called by the destructor of std::strstream


If str() was called on a dynamic strstream and freeze(false) was not called after
that, this destructor leaks memory.

// Run this code


#include <strstream>
#include <iostream>


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!
}


my_alloc(4096) called
1.23
my_free() called
my_alloc(4096) called
1.23

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.