std::strstreambuf:: ~strstreambuf
From cppreference.net
<
cpp
|
io
|
strstreambuf
C++
Input/output library
| I/O manipulators | ||||
| Print functions (C++23) | ||||
| C-style I/O | ||||
| Buffers | ||||
|
(C++23)
|
||||
|
(
C++98/26*
)
|
||||
|
(C++20)
|
||||
| Streams | ||||
| Abstractions | ||||
| File I/O | ||||
| String I/O | ||||
| Array I/O | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(
C++98/26*
)
|
||||
|
(
C++98/26*
)
|
||||
|
(
C++98/26*
)
|
||||
| Synchronized Output | ||||
|
(C++20)
|
||||
| Types | ||||
| Error category interface | ||||
|
(C++11)
|
||||
|
(C++11)
|
std::strstreambuf
| Public member functions | ||||
|
strstreambuf::~strstreambuf
|
||||
| Protected member functions | ||||
|
virtual
~strstreambuf
(
)
;
|
(C++98で非推奨)
(C++26で削除) |
|
std::strstreambuf
オブジェクトを破棄します。オブジェクトが動的に割り当てられたバッファを管理している場合(バッファ状態が「割り当て済み」)、かつオブジェクトがフリーズされていない場合、構築時に提供された解放関数、または提供されていなかった場合は
delete
[
]
を使用してバッファを解放します。
パラメータ
(なし)
注記
このデストラクタは通常、 std::strstream のデストラクタによって呼び出されます。
動的
strstream
に対して
str()
が呼び出され、その後
freeze(false)
が呼び出されなかった場合、このデストラクタはメモリをリークします。
例
このコードを実行
#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); } // デストラクタがここで呼び出され、バッファが解放される { std::strstreambuf buf(my_alloc, my_free); std::ostream s(&buf); s << 1.23 << std::ends; std::cout << buf.str() << '\n'; // buf.freeze(false); } // デストラクタがここで呼び出され、メモリリーク発生! }
出力:
my_alloc(4096) called 1.23 my_free() called my_alloc(4096) called 1.23