Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advantages/disadvantages of combining C# and C [closed]

Tags:

c

c#

winforms

dll

I am thinking about developing Winforms application that would use c library to preform all computations. I want to use C# because developing GUI with it is really easy, and C to increase performance. Are there other advantages or any disadvantages of combining those two languages?

Edit: As computations I mean mainly (but not limited to) graph algorithms, like coloring, dijakstra, maximum flow; I expect graphs to be huge, and performance is really crucial.

like image 240
Zaphood Avatar asked Dec 06 '22 18:12

Zaphood


2 Answers

and C to increase performance

You could write pretty well performing applications using pure managed code. Take for example this very same site. It's pretty darn fast, don't you think?

The way I see things is the following: mix those two technologies only if you are really some kind of a performance maniac (someone that tries to solve the scaling problems that Google does for example) or if you have some existing C codebase that you cannot port to .NET immediately and that you have to interoperate with.

In other cases, managed code is safer. If you are sick about performance don't forget that in many cases the cost of marshaling between managed and unmanaged code will be higher than the performance you would gain from pure unmanaged code. Also the JITter gets smarter and smarter with each version of the framework and maybe one day it will generate almost as efficient code as unmanaged code.

So, yeah, go for managed and leave C to the maniacs :-)

like image 155
Darin Dimitrov Avatar answered Dec 15 '22 00:12

Darin Dimitrov


I would not be so sure that C will be faster than C# for what you are going to do. The jitted code is extremely fast. Also, if you are doing lots of calculations, by using c#/.net, you could potentially take advantage of the Task Parallel Library, which would greatly ease parallelizing your calculations. And really, with all of the multi-core machines, I think that you will get a lot more bang for your bucks if you can take advantage of multiple cores (of course, straight C can thread as well, but the TPL in .net 4 is much more productive than the base WinApi)

One other thing that you might consider, and I am speaking from outside of my own experience, so definitely do your own research: I have heard that F# can be a very good choice for writing scientific sets/calculation libraries. I haven't written a line of F# myself, but from what I understand, the language design supports writing the calculations in a way that makes them extremely parallelizable.

(of course, now you have a new problem -- learning F# ;)

there is a post here that you might check out: F# performance in scientific computing

like image 38
JMarsch Avatar answered Dec 14 '22 23:12

JMarsch