473,378 Members | 1,309 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Writing std::iostream to MemoryStream

Hi,

I have an unmanaged iostream type that I need to copy to MemoryStream
(managed). Will appreciate if somebody can provide me the best/fastest
approach. This is what I have.

std::iostream *pStream = getStream();

//I need to copy the data pointed by pStream to MemoryStream
System::IO::MemoryStream ^mStream = gcnew System::IO::MemoryStream()

Thanks for the help.
Aug 2 '06 #1
2 2580
Haxan wrote:
I have an unmanaged iostream type that I need to copy to MemoryStream
(managed). Will appreciate if somebody can provide me the best/fastest
approach.
Probably you could call SetLength to set the MemoryStream's size, and
then pin its buffer and use iostream to read directly into MemoryStream.
Something like this should work:

System::IO::MemoryStream ^ mStream = gcnew System::IO::MemoryStream;
mStream->SetLength(bytes_to_read);
pin_ptr<unsigned charpp(&mStream->GetBuffer()[0]);
std::iostream * pStream = getStream();
pStream->read(reinterpret_cast<char*>(pp), bytes_to_read);

I've done the opposite before: I was writing to MemoryStream from
managed code, pinned it, and read its content from native code, and it
worked fine.

Tom
Aug 2 '06 #2
Thanks Tamas, that is really helpful.

"Tamas Demjen" wrote:
Haxan wrote:
I have an unmanaged iostream type that I need to copy to MemoryStream
(managed). Will appreciate if somebody can provide me the best/fastest
approach.

Probably you could call SetLength to set the MemoryStream's size, and
then pin its buffer and use iostream to read directly into MemoryStream.
Something like this should work:

System::IO::MemoryStream ^ mStream = gcnew System::IO::MemoryStream;
mStream->SetLength(bytes_to_read);
pin_ptr<unsigned charpp(&mStream->GetBuffer()[0]);
std::iostream * pStream = getStream();
pStream->read(reinterpret_cast<char*>(pp), bytes_to_read);

I've done the opposite before: I was writing to MemoryStream from
managed code, pinned it, and read its content from native code, and it
worked fine.

Tom
Aug 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: ernst.stiegler | last post by:
Hello, I just want to read a whole line from a console input. What I don't understand is that I always have to press ENTER twice in order to see the line I've entered. Here's my code : ...
7
by: Daniel Moree | last post by:
I'm working on a program that must first establish if the file exists in the program directory then it must open if for reading, read each line and set the variables then the program goes on about...
6
by: radnoraj | last post by:
Hi, I am sucessfull in redirecting console output to a file. but in this case nothing is displayed on the console, cout output is written to file without display. how do write the output to...
16
by: Simon Elliott | last post by:
If I include both of these headers in a c++ source file: #include <stdio.h> #include <cstdio> would I then be able to do both of: std::printf("Hello, world!\n"); printf("Hello, world!\n");
1
by: Ly Hoang Hai | last post by:
Hi all, I have just port my C++ 6.0 project into C++ project of Visual Studio.NET. However, .NET tell me that it can not find iostream.h. Some search on the internet tell me that I should change...
1
by: fuenfzig | last post by:
Hi all, I want to use a single std::stringbuf for writing (by a std::ostream) and for reading (by a std::istream), concurrently in two threads. This came to my mind, because the code for reading...
9
by: jerry.upstatenyguy | last post by:
I am really stuck on this. I am trying to write a string array containing a "word" and a "definition" to a class called Entry. Ultimately this will end up in another class called dictionary. No,...
8
by: jean.daniel.michaud | last post by:
Hi all, Something I don't get. The code is: // snippet on #include <list> #include <iostream> int main()
1
by: Twistfactory | last post by:
Hi all, I'm trying to implement a voice recording function. Basically it's supposed to record the WAV and write it out to the file, at which point LAME will kick in and convert it to MP3. The...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.