Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Shannon Barber

C++ memory stream

This topic is 5724 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!