• Advertisement
Sign in to follow this  

__asm in c#

This topic is 3774 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
You cannot directly inline assembly into C#, no, but you can call unmanaged code from managed code.

Chances are this is a bad idea anyway.

Share this post


Link to post
Share on other sites
c# is executed on a virtual machine and thus it is pointless to directly inline assembly code.

if you need the speed of assembly, use a native compiled language to begin with.

/thread

Share this post


Link to post
Share on other sites
You could emit MSIL instructions from your application, see the System.Reflection.Emit namespace. It's not the same thing, but at least somewhat similar.

Share this post


Link to post
Share on other sites
Only possible in C++/CLI.

You can move the routines requiring asm code into a C++/CLI library and call them in a C# project without much overhead (and certainly much less than P/Invoke would involve).

The implications will be that your assembly requires extended security privileges (problematic if you're doing a client-side browser component, eg. using Silverlight) and that your project will no longer be portable (embedded machine code cannot be executed on other platforms and last time I checked, mono supported pure CIL code only).

If you consider using asm for fast vecor or math math, don't do that. Better investige the native image generator (ngen.exe) and read Washu's blog to learn why you'll have a hard time beating .NET's own optimizer.

-Markus-


Share this post


Link to post
Share on other sites
Maybe the "pp" is short for "ppound".

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
Maybe the "pp" is short for "ppound".
Spot the WorseThanFailure reader!
[grin]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement