3 ms·
C# _targeting the .Net runtime_ is managed code. There are subsets, including Unity's new HPC#, that compile directly to assembly. I think it's important to se
by BinaryIdiot 8y ago
C# _targeting the .Net runtime_ is managed code. There are subsets, including Unity's new HPC#, that compile directly to assembly.
I think it's important to separate the language from the runtime so people come out less confused versus conflating them to cover the 90% use case.
- reitzensteinm 8y agoPedantically asserting that it's possible to use a subset of a language and feed it through a special compiler to write low level code is not the way to make it so people are less confused. We live in an era where you can boot Linux in JavaScript. If every time you make a statement about computing you have to list the exceptions, that's sinking in to the Turing tarpit for documentation.
- BinaryIdiot 8y agoNormally I'd agree with you, especially when concerned with languages like JavaScript. But C# is a different beast. It's being used quite frequently in large gaming projects and even operating systems where it is frequently less managed.You can even use it out of the box in a more, but obviously not entirely, unmanaged way to increase performance. I don't consider this pedantic in this case. But the line isn't hard so we'll have some disagreement how to teach / not teach this.
- reitzensteinm 8y agoDo you have any examples of projects where it's used in a "less managed" context? Are you just talking about avoiding GC, or something more advanced? Even when you write in a low level style using the .Net/Mono VM, you're still fully protected by the guarantees of the language and runtime. You can't chase bad pointers around through memory or overflow the stack. It's impossible to access an array without a bounds check unless the JIT can prove it's not needed. The safety this provides is night and day to what it's like coding close to the metal (I develop games in C# and have written a fair amount of C/asm). But as you say, we can agree to disagree about that...
- pjmlp 8y ago> You can't chase bad pointers around through memory or overflow the stack. It's impossible to access an array without a bounds check unless the JIT can prove it's not needed. Many native languages have these features without having a managed runtime.
- daeken 8y agoYou can absolutely do everything you described. You can use raw pointers in C#, to the extent that almost any C code can be converted 1:1 to C#. The memory safety goes out the window when pointers are in play; this is why we have 'unsafe' blocks.
- jayd16 8y agoI don't think you're giving C# enough credit in this case. We're not talking about a totally new language that uses the same syntax. This is just an AOT compile of efficient C#. The inefficient things are flagged as compiler errors instead of lint warnings. If you used the same code in a full .NET runtime deploy it would still be very efficient and most likely vectorized as well. Unity's Burst compiler is not nearly as mystical as their marketing team would have you believe at first glance.
- pjmlp 8y agoPeople are only confused if they keep mixing up languages with implementations, which are two different things.
- pjmlp 8y agoC# can also be compiled directly to Assembly via NGEN (only supports dynamic linking though), AOT compiler for WP 8.x, which was later replaced by .NET Native for UWP. .NET Core 3.0 will bring in CrossGen for AOT, and you also missed Xamarin/Mono support for AOT.