Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Hi,

I'm about to rewrite an old DLL containing several different calculation functions. The old version is done with VC6 and it's quite easily portable to newer formats.

However most of the software using these calculations are written in C#. So from the maintenance point of view it would be best to write them in C#.

I can accept a small performance downgrade but nothing severe. The calculations themselves are not difficult from programming point of view, just basic math operations. But they do contain lots of iterations (>10M).

So I would be interested to hear opinions if I should still stick to C++ or could I consider converting the library to C#. At the moment I feel that the performance wouldn't be an issue because of the nature of the calculations (iterations). JIT compiler should be involved only once and after that the rest of the operations are basically executing the same machine code. Any thoughts?

Thanks in advance,

mika
Posted
Comments
Albert Holguin 25-Mar-11 21:22pm    
I would say... update the code if its required, if you can reuse the code, then why not... C++ isn't going to disappear any time soon...

Depends on the usage. If it's a business application in which real time performance is not much of a concern, C# all the way. If it's a video game, then maybe you'll want to consider C++. I usually prefer code that is easy to maintain over code that is highly optimized when the optimization does not significantly improve the user's experience.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 25-Mar-11 16:22pm    
It depends, but my vote it 5 :-)
--SA
Wendelius 25-Mar-11 16:40pm    
Thanks for the answer! Forgot to mention it but it's a business app and the calculations are not updated in real-time but on the other hand users are not willing to wait for a 'long' time for the results. If you don't mind I'll mark this as accepted a bit later if someone still want's to jump in :)
Wendelius 26-Mar-11 3:44am    
Accepted, thanks again.
How often are the calculations called? Are they one time deals, or do they constantly get kicked off? What is the dll used for, meaning, what kind of software? In general, unless it is a latency sensitive project (trading, graphics intensive), you should be fine performance wise going to C#, at least based on my experience.

From a maintenance perspective is C# better because more developers on your team are familiar with it? If this is the case, how often would the calculations and/or dll need to be modified. If this is often, then the conversion to C# can save you a headache.

I have though, worked on projects where the GUI and form logic is all C#, while the heavy analysis was done through C++. This worked very well for our projects. Is there any other reason to move to C# other than maintainability?
 
Share this answer
 
Comments
Wendelius 25-Mar-11 16:43pm    
Thanks, very good questions! Your comments drive me even more towards C#.

As I wrote to AspDotNetDev, I'll mark this as accepted after a while :)
Wendelius 26-Mar-11 3:44am    
Accepted, thanks again.
Another consideration is whether your code is proprietary. If you don't want others to have the source, then maybe you should keep it packaged it in a DLL. If you do that, the language is a non-issue, since no one but you will see it.
 
Share this answer
 
v3
Comments
Wendelius 26-Mar-11 3:38am    
Thank you! That's a good point. The code is proprietary but it's not part of a product but used only in-house so in this sense the security isn't an issue.
Wendelius 26-Mar-11 3:44am    
Accepted.
I think one more thing to mention is that unless your c++ code is using SSE to optimise the calculations then it's C# equivalent is likely going to perform the same or with negligible difference.

So I don't think the difference in performance should affect your decision on which language to use, although if it is an issue you could always do a few benchmarks between the two.
 
Share this answer
 
Comments
Wendelius 26-Mar-11 3:43am    
Thanks! SSE isn't used. I agree that the performance most likely isn't going be much worse so C# sounds very tempting.
Wendelius 26-Mar-11 3:44am    
Accepted.
C++ and C# are different for the way memory is managed.
Primitive number type calculation translate the same, when becoming machine code.

If the problem is efficiency in calculation, the real problem is not the language, but the way the compiler optimize the code respect to the underlying processor.
But this is something dealing with the compiler backed (the machine code generator of the native C++ compiler or the JIT compiler, in case of .net languages) than fronted (syntax and semantics).
 
Share this answer
 
Comments
Wendelius 26-Mar-11 5:40am    
Thanks for the comments. The calculations need to be 'fast' but of course fast is very relative. I'm trying to balance the performance against the maintainability (achieveing more homogenous environment). You're right that if I go to C# I'll have a close look, what kind of programming structures I'll use.
Wendelius 26-Mar-11 5:41am    
Accepted.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900