std::strstreambuf:: freeze
From cppreference.net
<
cpp
|
io
|
strstreambuf
|
void
freeze
(
bool
freezefl
=
true
)
;
|
(C++98에서 사용 중단됨)
(C++26에서 제거됨) |
|
버퍼가 동적 할당을 사용하는 경우, 스트림의 고정 상태를 freezefl 로 설정합니다.
스트림이 동결된 동안,
overflow()
는 버퍼를 재할당하지 않으며
destructor
는 버퍼를 해제하지 않습니다 (따라서 메모리 누수가 발생합니다).
목차 |
매개변수
| freezefl | - | 동결 상태를 설정할 새 값 |
반환값
(없음)
참고 사항
str() 함수를 호출할 때마다 반환되는 포인터의 유효성을 보존하기 위해 스트림이 고정됩니다. 소멸자가 버퍼를 해제할 수 있도록 하려면 freeze ( false ) 를 명시적으로 호출해야 합니다.
예제
이 예제에서 기본 배열의 초기 할당은 16바이트였습니다.
이 코드 실행
#include <iostream> #include <strstream> int main() { { std::strstream dyn; // dynamically-allocated read/write buffer dyn << "Test: " << 1.23; // note: no std::ends to demonstrate append behavior std::cout << "dynamic buffer holds " << dyn.pcount() << " characters: '"; std::cout.write(dyn.str(), dyn.pcount()) << "'\n"; // the buffer is now frozen, further output will not make the buffer grow dyn << "more output, hopefully enough to run out of the allocated space" << std::ends; std::cout << "After more output, it holds " << dyn.pcount() << " characters: '" << dyn.str() << "'\n"; dyn.freeze(false); // unfreeze before destructor } // memory freed by the destructor { char arr[20]; std::ostrstream st(arr, sizeof arr); // fixed-size buffer st << 1.23; // note: no std::ends to demonstrate append behavior std::cout << "static buffer holds " << st.pcount() << " characters: '"; std::cout.write(st.str(), st.pcount()); std::cout << "'\n"; st << "more output, hopefully enough to run out of the allocated space" << std::ends; std::cout << "static buffer holds " << st.pcount() << " characters: '"; std::cout.write(st.str(), st.pcount()); std::cout << "'\n"; } // nothing to deallocate, no need to unfreeze, }
출력:
dynamic buffer holds 10 characters: 'Test: 1.23' After more output, it holds 16 characters: 'Test: 1.23more o' static buffer holds 4 characters: '1.23' static buffer holds 20 characters: '1.23more output, hop'
참고 항목
|
자동 재할당을 비활성화/활성화합니다
(
std::strstream
의
public member function)
|
|
|
자동 재할당을 비활성화/활성화합니다
(
std::ostrstream
의
public member function)
|
|
|
[virtual]
|
strstreambuf
객체를 파괴하며, 선택적으로 문자 배열을 할당 해제합니다
(virtual public member function) |
|
[virtual]
|
출력 시퀀스에 문자를 추가하며, 동적이고 고정되지 않은 경우 버퍼를 재할당하거나 초기 할당할 수 있습니다
(virtual protected member function) |