News for hackers. Stuff that matters.
Re:Introducing .NET IL Linker by int_19h on Thursday August 31, 2017 @02:04AM (#15138442)
The nice thing about C# is that, unlike Java, you actually get all the low-level things. They're just tucked away, out of sight of your average coder who's more likely to shoot themselves in the foot with them. But if you know how to use them, it's all there. Let me enumerate.

C# has value types, which follow the same memory model as in C (i.e. stack-allocated for locals, embedded directly into the outer object as fields). You can request explicit layout mode, whereby you can set an offset for every field manually - if you set them all to zero, you get a C union. Alternatively, you can request automatic layout mode, where the JIT is allowed to reorder the fields in arbitrary ways to optimize memory and/or access, which is something you don't even get in C.

It has raw pointers. Unlike object references, these have the usual C semantics - there's no GC involved there, and you're responsible for keeping the objects alive, so you can have dangling pointers etc. No boundary or null checks, either - it's zero overhead. You can do pointer arithmetic on them, including indexing with []. If you P/Invoke malloc or equivalent, this gives you C-style heap allocated arrays.

It has stackalloc, which is a language operator that's equivalent to the non-standard alloca() function in C - allocate a chunk of memory on the stack, and return a pointer. This immediately gives you stack-allocated arrays as flexible as C99 VLAs.

With generics, if a generic type parameter is a value type, the specialization for that type is separately JIT-compiled and optimized. This can be used in a way very similar to C++ templates, for zero-overhead inlined callbacks and similar shenanigans.

All in all, if you want to write high-perf code in C#, you certainly can. You'll hit the limits of the JIT optimizer soon enough - it can't be as good as a full-fledged AOT C++ compiler, say - but you can certainly shed most of the overhead associated with a managed language.

Re:Introducing .NET IL Linker by luch on Thursday August 31, 2017 @03:40AM (#15138780)
You can even wrap native Win32 code in a CLR dll : https://msdn.microsoft.com/en-us/library/ms235281.aspx

The binding is a bit funky (lots of `ref` and `gcnew` keywords sprayed here and there) but it works.

Re:Introducing .NET IL Linker by pjmlp on Thursday August 31, 2017 @02:31AM (#15138545)
In Java some of them are there, although the Unsafe package is not sanctioned, and marked to be replaced by something safer that can provide the same capabilities (e.g. VarHandles on Java 9).

As for the rest at least we can hope Java 10 brings them.

You missed a few C# goodies from 7.0 up to 8.0, coming from the experience with Midori.

Re:Introducing .NET IL Linker by int_19h on Friday September 01, 2017 @05:46AM (#15147213)
The goodies in question are local refs and ref returns, right? Which really only make a difference when you're writing memory safe code. If you're dropping down to "unsafe" and manual memory management for other things, then refs don't do anything that raw pointers don't.
Re:Introducing .NET IL Linker by pjmlp on Friday September 01, 2017 @07:00AM (#15147428)
There are other goodies, like memory views, blittable structs, interior pointers and readonly refs.

https://github.com/dotnet/roslyn/blob/master/docs/Language%2...