C++ memory stream
Using stringstream''s read & write method you can use it as a binary memory stream, but it allocates memory off the heap to do this. Is there any way to use space on the stack instead?
Is there an adaptor to let you use a container as a stream target? If so, I know boost has a class the turns a stack array into an stl compatible container.
a) Custom allocator policy class (e.g. pool)
b) Not that I am aware of. Only the other way round (stream iterators). Usually, algorithms (e.g. std::copy) do the connection between streams and containers.
There is the problem that output operators do not have comparisons semantics. Therefore, you can't test for the end of the container. Which means that the container must be able to grow arbitrarily. Which means dynamic allocation.
Otherwise, you might be able to write a stream buffer adaptor for arbitrary containers. Might not work the way you want (actual stream usage of the buffer), but it is possible to switch std::stringstream's stream buffer to something else.
Might not be pretty though.
Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
[edited by - Fruny on October 18, 2002 12:27:29 AM]
b) Not that I am aware of. Only the other way round (stream iterators). Usually, algorithms (e.g. std::copy) do the connection between streams and containers.
There is the problem that output operators do not have comparisons semantics. Therefore, you can't test for the end of the container. Which means that the container must be able to grow arbitrarily. Which means dynamic allocation.
Otherwise, you might be able to write a stream buffer adaptor for arbitrary containers. Might not work the way you want (actual stream usage of the buffer), but it is possible to switch std::stringstream's stream buffer to something else.
Might not be pretty though.
Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
[edited by - Fruny on October 18, 2002 12:27:29 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement