|
-
Nov 5th, 2004, 12:45 PM
#1
Thread Starter
Frenzied Member
Set a stream to global memory
What is the best was to set a stream to global memory but have the flexibility to use the same kind of stream to read from a file?
I tried this:
filebuf fb;
fb.setbuf((char*)pBuffer, ::GlobalSize(hGlbl));
istream* s(fb);
this->FromStream(s);
But I cannot access setbuf. And I don't want to use IStream. I cannot compile it and I didn't see any MS reference to the lib it is defined in.
Last edited by aewarnick; Nov 5th, 2004 at 12:53 PM.
-
Nov 5th, 2004, 03:17 PM
#2
Thread Starter
Frenzied Member
I guess what I need is some kind of memory stream to be able to set a pointer to the data and then set the size of the data within the stream like I tried above.
-
Nov 5th, 2004, 03:35 PM
#3
Thread Starter
Frenzied Member
What would be perfect I think is a strstream but it is depreciated!
-
Nov 5th, 2004, 05:36 PM
#4
stringstream still exists. You only need to create a std::string from the memory:
Code:
std::istringstream stream(std::string(pBuffer, pBuffer+GlobalSize(hGlbl)));
Mind you, this COPIES the memory. You could also allocate the string with a custom allocator type that refers only to this memory block. The problem with that lies in the way allocators are handled, as they effectively can't have state.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 5th, 2004, 09:55 PM
#5
Thread Starter
Frenzied Member
How would I create a string and set it to that memory block and what is the problem with not having state?
Last edited by aewarnick; Nov 5th, 2004 at 10:30 PM.
-
Nov 7th, 2004, 02:37 PM
#6
The first is very hard without the second. That should answer both questions, if you read up on what allocators do.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|