Results 1 to 6 of 6

Thread: Set a stream to global memory

  1. #1

    Thread Starter
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037

    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.

  2. #2

    Thread Starter
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037
    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.

  3. #3

    Thread Starter
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037
    What would be perfect I think is a strstream but it is depreciated!

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  5. #5

    Thread Starter
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037
    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.

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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
  •  



Click Here to Expand Forum to Full Width