[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.sdk

How to integrate C in a C# project?

Yawen Chan

10/16/2002 2:45:00 AM

Hi,

I'm writing a C# project and want to use C codes for some algorithms and
calculations to enhance performance. I'm sure there are a lot of examples
on the web, can someone point me to those sites (I did quite some research
but couldn't find anything useful)?

I think I can use a DLL written in C in a C# project. Is there any other
ways to include C in C# other than using the DLL approach?

Thanks very much.

Yawen


4 Answers

Chris R. Timmons

10/16/2002 2:55:00 AM

0

"Yawen Chan" <y3chan@engmail.uwaterloo.ca> wrote in
news:OjiITWLdCHA.1652@tkmsftngp09:

> Hi,
>
> I'm writing a C# project and want to use C codes for some
> algorithms and calculations to enhance performance. I'm sure
> there are a lot of examples on the web, can someone point me to
> those sites (I did quite some research but couldn't find
> anything useful)?
>
> I think I can use a DLL written in C in a C# project. Is there
> any other ways to include C in C# other than using the DLL
> approach?

Yawen,

C# code can be just as fast as C code. Using "unsafe" code, C#
can use pointers and directly manipulate memory just like C can.
Before you go to the trouble of trying to incorporate C code in a
C# program, I would suggest running some performance tests in C#.
It may be fast enough for your purposes.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmo...

Yawen Chan

10/16/2002 3:20:00 AM

0

Hi Chris,

Thanks for your reply. I'm writing a program to do some manipulation with
bitmap images. I know that I can use pointers to enhance the performance,
but I also want to get rid of the OO way when I'm using the primitive types
such as int and double to perform calculation and comparison. I'll sure run
some performance tests, but I also want to know what's the other way of
doing it.

Thanks.

Yawen

"Chris R. Timmons" <crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote in message
news:Xns92A8D5114D3ADcrtimmonscrtimmonsin@207.46.239.39...
> "Yawen Chan" <y3chan@engmail.uwaterloo.ca> wrote in
> news:OjiITWLdCHA.1652@tkmsftngp09:
>
> > Hi,
> >
> > I'm writing a C# project and want to use C codes for some
> > algorithms and calculations to enhance performance. I'm sure
> > there are a lot of examples on the web, can someone point me to
> > those sites (I did quite some research but couldn't find
> > anything useful)?
> >
> > I think I can use a DLL written in C in a C# project. Is there
> > any other ways to include C in C# other than using the DLL
> > approach?
>
> Yawen,
>
> C# code can be just as fast as C code. Using "unsafe" code, C#
> can use pointers and directly manipulate memory just like C can.
> Before you go to the trouble of trying to incorporate C code in a
> C# program, I would suggest running some performance tests in C#.
> It may be fast enough for your purposes.
>
> Chris.
> -------------
> C.R. Timmons Consulting, Inc.
> http://www.crtimmo...


Thong Nguyen <tum(NOSPAM

10/16/2002 7:16:00 AM

0

Hi there,

Primitive types like bool and char aren't manipulated as objects by the CLR.
The Jitter will optimize them nicely :).

There are some options for including C code inside C#.

+ Put the C code inside a DLL. Access the exported functions through
P/Invoke.
+ Put the C code inside a COM object. Access through COM interop. [This
approach won't be cross platform]
+ Use Managed C++ to write your code (conversion from C -> C++ is trivial).
[This approach also won't be cross platform]

I'd recomend using a DLL since it is the cleanest and most cross platform.
COM and MC++ don't have reliable non-windows implementations.
You might find the MC++ is faster than the DLL approach since it elimiates
some of the P/Invoke overhead. Profiling might help determine if it is
worth the it.

^Tum

"Yawen Chan" <y3chan@engmail.uwaterloo.ca> wrote in message
news:OjiITWLdCHA.1652@tkmsftngp09...
> Hi,
>
> I'm writing a C# project and want to use C codes for some algorithms and
> calculations to enhance performance. I'm sure there are a lot of examples
> on the web, can someone point me to those sites (I did quite some research
> but couldn't find anything useful)?
>
> I think I can use a DLL written in C in a C# project. Is there any other
> ways to include C in C# other than using the DLL approach?
>
> Thanks very much.
>
> Yawen
>
>


Yawen Chan

10/16/2002 7:34:00 AM

0

Thanks a lot Thong, you give a nice overview of what can be done. I'll
write some simple apps and see which way suits my need. I'll also try to
write the algorithm in C# and see the difference in performance. Thanks
again. This really helps.

Yawen

"Thong Nguyen" <tum(NOSPAM)@veridicus.com> wrote in message
news:uiyR3tNdCHA.2392@tkmsftngp08...
> Hi there,
>
> Primitive types like bool and char aren't manipulated as objects by the
CLR.
> The Jitter will optimize them nicely :).
>
> There are some options for including C code inside C#.
>
> + Put the C code inside a DLL. Access the exported functions through
> P/Invoke.
> + Put the C code inside a COM object. Access through COM interop. [This
> approach won't be cross platform]
> + Use Managed C++ to write your code (conversion from C -> C++ is
trivial).
> [This approach also won't be cross platform]
>
> I'd recomend using a DLL since it is the cleanest and most cross platform.
> COM and MC++ don't have reliable non-windows implementations.
> You might find the MC++ is faster than the DLL approach since it elimiates
> some of the P/Invoke overhead. Profiling might help determine if it is
> worth the it.
>
> ^Tum
>
> "Yawen Chan" <y3chan@engmail.uwaterloo.ca> wrote in message
> news:OjiITWLdCHA.1652@tkmsftngp09...
> > Hi,
> >
> > I'm writing a C# project and want to use C codes for some algorithms and
> > calculations to enhance performance. I'm sure there are a lot of
examples
> > on the web, can someone point me to those sites (I did quite some
research
> > but couldn't find anything useful)?
> >
> > I think I can use a DLL written in C in a C# project. Is there any
other
> > ways to include C in C# other than using the DLL approach?
> >
> > Thanks very much.
> >
> > Yawen
> >
> >
>
>