std::strstreambuf:: freeze
|
void
freeze
(
bool
freezefl
=
true
)
;
|
(obsoleto en C++98)
(eliminado en C++26) |
|
Si el búfer utiliza asignación dinámica, establece el estado de congelación del flujo a freezefl .
Mientras el flujo está congelado,
overflow()
no reasignará el búfer y el
destructor
no liberará el búfer (causando así una fuga de memoria).
Contenidos |
Parámetros
| freezefl | - | nuevo valor para establecer el estado de congelación |
Valor de retorno
(ninguno)
Notas
Cada llamada a str() congela el flujo para preservar la validez del puntero que devuelve. Para permitir que el destructor desasigne el búfer, freeze ( false ) debe llamarse explícitamente.
Ejemplo
En este ejemplo, la asignación inicial del array subyacente fue de 16 bytes.
#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, }
Salida:
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'
Véase también
|
deshabilita/habilita la reasignación automática
(función miembro pública de
std::strstream
)
|
|
|
deshabilita/habilita la reasignación automática
(función miembro pública de
std::ostrstream
)
|
|
|
[virtual]
|
destruye un objeto
strstreambuf
, opcionalmente desasignando el arreglo de caracteres
(función miembro pública virtual) |
|
[virtual]
|
agrega un carácter a la secuencia de salida, puede reasignar o asignar inicialmente el búfer si es dinámico y no está congelado
(función miembro protegida virtual) |