MichalStrehovsky / zerosharp

Demo of the potential of C# for systems programming with the .NET native ahead-of-time compilation technology.
2.02k stars 105 forks source link

Isn't DllImport slow? #27

Open Shadowblitz16 opened 2 years ago

Shadowblitz16 commented 2 years ago

Isn't DllImport slow? Would this even be viable for os dev?

MichalStrehovsky commented 2 years ago

You can see for yourself in the disassembly.

This line:

https://github.com/MichalStrehovsky/zerosharp/blob/186dc165ec5cce3033200e1d4177b9bbb89fb7d9/no-runtime/build.cmd#L38

(--directpinvoke:kernel32)

makes all DllImports statically bound. They have the same overhead as an extern DllImport in C (they go through a single jmp instruction on x64).