How to make C++ Buffer used pre-defined adress for its internal buffer

Hello,

in order to avoid copying operations, I want to construct a stream which uses a pointer passed by me as an argument for its internal buffer.

What I want to do is:
I've got an incoming stream of data (a http response, to be precise) which is passed on to a Parser (which only accepts and returns arrays).

I have to call stream->str(); before to get the data for the Parser, which copies the streams entire content into a String.

What I'd like is something of the sort
stream = new std::stringstream( myBuffer );
so that I can pass myBuffer to the Parser.
However, I don't know how large the incoming data is, so I don't want to construct an Array of fixed size.

Oh, and stream->rdbuf()->pubsetbuf(); doesn't work with the VS2008 STL...

Has anyone encountered a similar problem and found a solution?


It seems you're thinking about this too hard my friend. Check this out: http://www.cplusplus.com/reference/stl/vector/

Vectors populate a dynamically sized array with what ever data type you want to assign to them. If this is a live stream from a website then I'd be curious to see what you were planning on using to buffer that data anyway.

Something in my gut tells me that you're not using a true "handshaking" protocol for this little venture and your source is just going to be vomitting data at you. So to preserve it's integrity I'd suggest looking into Multi-Threading. It's a bit beyond the ability of a beginner but as I'll get into later, so is your project. SFML makes it really easy, but the Windows API is only slightly more complicated and from what I've used of it, it's better suited for the Windows environment.

You won't get much in the way of responses in the beginner section for questions like this. As soon as you get into interprcess communication, other then the OS to your program and back again, you should post in the General C++ section.
Last edited on
Topic archived. No new replies allowed.