Skip to main content
gamedev.net
🔒 Locked

Using strstreambuf with istream

Started by DragonGeo2 Jun 26, 2010 at 5:02 AM 0 replies 900+ views
Original Post
DragonGeo2
DragonGeo2
So I was looking for a way to "map" a std::istream to a memory-mapped file (without copying the memory) when I came across this post:
http://www.gamedev.net/community/forums/viewreply.asp?ID=3521298

I said to myself, "alright that doesn't sound too bad" and whipped this up:
std::strstreambuf buffer;buffer.pubsetbuf( (char*)descrip.filedata, descrip.filesize);std::istream is(&buffer);// pass is to a library function here
I have two problems with this code, one is that I don't like casting descrip.filedata from a (const unsigned char*) to a (char*). The other problem I have is that the code crashes within the library function call that takes is as a parameter.

So firstly, what am I doing incorrectly to trigger this crash (because I honestly have no idea how to use a strstreambuf)? And secondly, is there some sort of an "istrstreambuf" that I could use so I wouldn't have to cast away the const in the filedata buffer?
DragonGeo2
DragonGeo2
Nevermind, I fixed it myself!

Solution code:
std::strstreambuf buffer(descrip.filedata, descrip.filesize);std::istream is(&buffer);// pass is to a library function here

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.