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