[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

io speed c# c++

Posted on 2005-04-07
7
Medium Priority
?
457 Views
Last Modified: 2012-06-21
Hi,
Could you please tell me which is the fastest method of io? I am currently using a binary writer in c#. Is it worth using streams such as fstream in mc++ or c++, using interoperability.
 I am looking for performance mainly for int's and float's. For example to write and read an array of 1million floats, I need the fastest method.
thanks in advance
0
Comment
Question by:dm14011
7 Comments
 
LVL 6

Expert Comment

by:melodiesoflife
ID: 13732574
If you prefer about performance, don't use C#. C++ is the best choice.
0
 
LVL 9

Accepted Solution

by:
rcarlan earned 2000 total points
ID: 13733354
You should look into memory mapped files. They are the fastest means of file I/O in Windows (as far as I know).
With memory mapped files, you basically read/write from memory and leave the flushing to/reading from file to the virtual memory manager. Flushing to file is done by background threads - the ones used by the virtual memory manager for paging.
Memory mapped files are particularly good when you need random access in large files.

Radu
0
 
LVL 10

Expert Comment

by:NetworkArchitek
ID: 13735696
C++ is certainly the fastest, it is completely unmanaged. But this is theoretically true, in many applications you won't see a benefit unless you are writing a *lot* of code that gets right to the mettle. I would like to see someone take a 1ghz machine and write this application in c++ and c# and benchmark it. My guess is the performance difference would be negiligible. I was just commenting on the idea of c++ vs c#, in practice Rcarlan has the best solution.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 9

Expert Comment

by:rcarlan
ID: 13740786
One thing that I've noticed is very expensive in C# (at least in VS.NET 2003) is throwing and catching exceptions. And I know this also applies to Java.

Exceptions are expensive in any language (which is why some prefer to use SEH rather than C++ exceptions), but, based on the tests I've done, C# seems an order of magnitude slower than C++. I assume it's due to the managed environment - i.e. managed C++, VB.NET, J# would all suffer in the same way.

Radu
0
 

Author Comment

by:dm14011
ID: 13741801
Hi again. thanks for your comments. This is all very interesting. Just to expand a bit, I have an io intensive application that aims to potentially access dynamically up to several billion values in its lifetime. (the values must remain in case they are reaccessed. They are also changeable by the user and hence must be saved and reloaded and not just be stored by a function or reallocatable). I much prefer to use c# because of its production rate and ease of use. Ill have a look at the memory mapped files. That sounds good - thanks. As NetwrokArchitek mentioned I'm not sure how c# and c++ compare. I might do a little benchmarking myself and see what happens. I also currently have interop costs to consider, which may slow things. Maybe Ill get back with some of the results of my tests. Until then if anyone has any more ideas of comments then please post . Also is ifstream and ofstream the fastest i/o in c++, oris there anything in c, or any other classes/functions which are faster/more efficient?
cheers
0
 
LVL 9

Expert Comment

by:rcarlan
ID: 13741825
I don't think ifstream and ofstream will beat memory mapped files.

The interop is costly. If your native app is C#, stick with C#. You will lose more by doing interopo between managed and unmanaged code, than you'd gain from coding the I/O in C++.

Radu
0
 
LVL 10

Expert Comment

by:NetworkArchitek
ID: 13744046
Yeah, memory mapped files are the way to go. Actually, this isn't necessarily an either or situation. I haven't done this with C++ but I have with C# and VB, and I know you can do it in VS 03 but it works even better in '05, you can mix projects. You can write the bulk of the app in C# and then write the i/o intensive stuff in C++. Its completely seemless with C# and VB so you may want to look on MSDN for how to do it successfully with C++, as I haven't tried it. This might be a good compromise. And just to reinforce what Rcarlan said, Interop is very expensive, I only use it if there is no other way to do it.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month18 days, left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question