Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any performance hit or thread context switch on using unsafe code?

Tags:

c#

.net-4.0

If I want to use a bit of unsafe code inside a very time sensitive app - will be there any delay in 'swiching' to unsafe code or thread context switch? C# .net 4

like image 353
Boppity Bop Avatar asked Dec 12 '22 08:12

Boppity Bop


1 Answers

In principle: no. The whole point is that you bypass some of the managed runtime checks and restrictions.

That said, it is theoretically possible that the JIT engine can apply fewer optimizations in rare circumstances, due to the fact that fewer assumptions can be made about the code in the unsafe block. Edit Actually the point about pinning heap memory made by Matthew is a prime example that lies in this direction. The JIT-ter and GC engine are more restricted and can make fewer assumptions

Also, unsafe code requires running with certain permissions so it might not be appropriate for all deplyoment targets.

like image 185
sehe Avatar answered Dec 14 '22 21:12

sehe