C++ memory stream

Started by
0 comments, last by Shannon Barber 21 years, 6 months ago
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.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Advertisement
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]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement