Lurker News

Comments (137) 32 threads

Show all comments

Showing thread 1 of 32

raincole6 replies#
C# already provides many tools for your performance-critical code though. You can use pointers in unsafe. You can allocate unmanaged memory with Marshal. You can avoid copy with Span. You can even manually vectorise with Vector.IsHardwareAccelerated and such.

You can also distribute apps without .NET runtime with NativeAOT.
I'm sure there are people who want a C# without GC, but for me it's just... sufficient enough.

Waraqa3 replies#
NativeAOT can't compile for DOS.
raincole#
I... guess so? But the last time I had users who use DOS was in my previous life. NativeAOT supports iOS though, which is a reasonable target for the current-life me.
dragonwriter#
Which would be a problem if I needed to write code today and send it back to the 1990s to be run, but I have about as much need to compile to DOS as I need to produce punch cards to load into ENIAC.
to11mtm1 reply#
I know it's a bit contrived as far as making it work, but doesn't SeeSharpSnake [0] have a DOS compile option?

Hell, I'll be bold and say, if there's a worthwhile AI credit sink, it would be just adding it all properly as a bolt on or similar to NativeAOT.
[0] - https://github.com/MichalStrehovsky/SeeSharpSnake

reverseblade2#
DOS yes, 386: no
samuelknight#
NativeAOT gets rid of JIT not GC. The language is rich enough that you can avoid making garbage though.
randomNumber71 reply#
> I'm sure there are people who want a C# without GC

There's also C++ and although it is a monstrosity the practical thing would be to use that.
If you want a serious alternative to C++ I don't see it in C# without GC. On the other hand I have seen a lot of C++ code where normal C# would be much better suited.

DeathArrow#
>There's also C++ and although it is a monstrosity the practical thing would be to use that.

True, but can't you work with a subset of C++ that you consider sane?

jeremyjh2 replies#
Also people expect when they use a C# compiler that existing programs and libraries written in C# will be usable, but this doesn’t appear to support the same standard library APIs. So why use C# at all instead of a language with an ecosystem that has the properties you want?
DANmode1 reply#
Such as?
jeremyjh2 replies#
C++, Rust or Zig

Continue this thread — 2 replies

dragonwriter#
I mean, unless you don’t need any memory to be released during a run, everything needs to be rewritten to use memory management through arenas, which is a whole new memory management paradigm even for most people used to languages which require either manual memory management or highly specific lifetime specifications. So, yeah, no nontrivial existing code is usable even before you consider that none of the libraries supplied by the runtime that most code relies on are available.
lowbloodsugar1 reply#
.NET runtime also has generational GC and escape analysis (so objects can be allocated on the stack if they have a known lifetime). Generational GC essentially give you a super fast bump allocator for short lived objects: faster than malloc.

Even without unsafe we can allocate objects once and just reuse them. But why would you? C# is the go to for interfacing with native code and unmanaged memory. ( C# is way ahead of Java tho JDK 25 is beginning to catch up). I miss C#.
Figure out what parts of your app needs to be “downcoded” and optimize that. Enjoy bump allocators and plentiful libraries for the rest of it.
I wrote graphics applications in C# that used 3GB of memory back when we had to tell XP, at boot, to not use half the 32bit address space for itself. Most of it was in unmanaged space. C# is awesome.

pjmlp#
Having to spend quite some time with Node.js nowadays, I miss both Java and C# regularly.
a3w2 replies#
Isn’t marshaling about network representation, so the same concept as javas Parcelable tries to solve ?
chews#
sorta.. if you're thinking gRPC and Protobuf, but because they're on the same machine and often in the same process, it's a pointers-wizzeled interface all provided by the layers it was built on... then it just maps types, responses, and their interfaces. P/Invoke is wizardry.
raincole1 reply#
In C# (and generally in programming) marshaling is the conversion between your typical memory representation (in C# it's your object) and the other ways (be it C struct, C string, utf8 string, or whatever received from socket.) that's why AllocGlobal is under Marshal. Not saying one should use it though... the only ones sane programmers would touch is probably to handle C structs returned from native code.
jasomill#
System.Marshal is a sort of catch-all for functions used to interact with unmanaged code, including things like Win32 error handling and COM in addtion to type conversion and unsafe memory access in general.