6 ms·
Excellent GUI frameworks on most platforms. Much better unmanaged interop story: [DllImport] (btw it works on all platforms, e.g. on Linux it imports from .so
by Const-me 9y ago
Excellent GUI frameworks on most platforms.
Much better unmanaged interop story: [DllImport] (btw it works on all platforms, e.g. on Linux it imports from .so libraries), structures, unsigned integers.
Better multithreading: thread pool, synchronization contexts, async-await.
Unsafe code, pointer arithmetic.
LINQ
- int_19h 9y agoSpeaking of interop - the nice thing about .NET type system, is that it has facilities to do complete mapping to C, with the sole exception of setjmp/longjmp (which is generally a sore point with everything, even C++ doesn't handle it well). You already pointed out unsigned integers and structs; it's also worth pointing out raw (non-GC-aware) pointers, and explicit layout structs; the latter can handle C unions seamlessly, in particular (you just say that all fields have offset 0).
- Const-me 9y agoVariable-length C structures don’t map. Example of such structure: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365521(v=vs.85).aspx https://msdn.microsoft.com/en-us/library/windows/desktop/aa3... But they’re rarely found in APIs, and there’s Marshal class in the framework to implement manual marshaling by reading/writing stuff at unmanaged memory addresses, even without /unsafe compiler switch.
- int_19h 9y agoWith a little syntactic sugar in C#, they do map, in the same exact way you do this in C - you just use a "fixed" array of one as the last element: struct VariableLength { public int fixedSize; public fixed int varSize[1]; } Of course, this also means that you have to use stackalloc or other manual allocation to actually get a properly sized block of memory, computing said size yourself; but you also have to do it in C with malloc: byte* p = stackalloc byte[sizeof(VariableLength) + 10 * sizeof(int)]; var vl = (VariableLength*) p; Once you have a pointer, though, you can do vl->varSize[i] etc - this works because the type of vl->varSize when you access it is int*.
- oceanswave 9y agoCame here to say this — one of my first projects in the industry as an intern way back with .net 1.1 was to create an c# based application to parse through effectively binary serialized variable sized c structs.
- int_19h 9y ago"fixed" was a C# 2.0 addition, though. Back in 1.x days, you basically had to declare that field as a simple scalar instead, and then use & to manually obtain the pointer (but then you could index it with [] etc, same as in C, so it doesn't really make that much of a difference in this case; "fixed" sure did come in handy for other stuff though).
- pjmlp 9y agoYeah, Mark Reinhold already stated multiple times that JNI was designed on purpose to be hard, because Sun wanted to drive people away from writing unmanaged code. Thanks to JRuby guys and Project Panama, Java will eventually get a .NET like interop story, but it is still in the future. :(
- peoplewindow 9y agoWow when did he say that?
- pjmlp 9y agoAt the JavaOne 2013 Technical Keynote. https://blogs.oracle.com/java/the-javaone-2013-technical-keynote https://blogs.oracle.com/java/the-javaone-2013-technical-key... <quote> He mentioned JNI 2.0 and said, “It just shouldn’t be so hard to integrate Java with native code after all these years.” </quote> For the full context, you need to watch the keynote.
- Const-me 9y agoSearched a bit on Project Panama, found an example: @Header(path="unistd.h") While indeed very easy to use, that API is extremely hard to implement in the runtime to make it work not just for toy examples. Authors of real world libraries do all kinds of weird stuff in their C headers: they abuse C preprocessor, implement compiler-specific hacks, and even include pieces generated by external tools.
- zaphirplane 9y ago> Excellent GUI frameworks on most platforms. Is platform_s_ here, Windows 10, Windows 8 and other ms platforms Last time I looked GUI on Mac and Linux was far from excellent something on par with python binding to QT/gtk works but not enjoyable