Posted by reverseblade2 5 hours ago
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.
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.
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.
GC is not surrendering control. That seems to be HN's #1 bug bear. The sensation that someone or something is taking control away from you. The proper way to frame this is that you can actually focus on the original problem you set out to solve. Risking memory leaks is crazy when it's not something the customer is demanding. Even in gaming I think the GC is fine. There are ways to spread the impact across frames and bound the amount of time spent collecting.
If your clever scheme wouldn't work with a GC-managed heap, it probably won't work with one managed by hand either.
But it really depends on what you're doing. You can use the wrong tool for a job, but you can also use the right tool. It depends on the job.
I'm not saying manage memory manually. You can switch to a language that is reference counted. Then at least that abstraction guarantees deterministic deallocation.
That comes with another set of trade-offs such as having to pay attention to atomic reference counts, making sure there's no cycles, maybe even treating some graphs as arenas to avoid chained deallocations, but the abstraction itself is designed to be deterministic and is more easily controlled.
One does not have to live with the tradeoffs that C#'s default GC makes. One just needs to understand how the GC works and how it is controlled.
To be fair, it is also probably the number one cause of long hitches in poorly optimized UE games, and also the main contributor to class of use-after-free bugs (persisted native pointers and references to objects that weren't properly added to the object graph, though goes away with proper usage of weak object pointers and the like) so it is very much a double-edged-sword.
Agreed that it’s no longer a bottleneck for games; profile—and-optimize approaches are very effective and the tooling has never been better.
Or rather GC done explicit.
You control when and where and how garbage gets collected in various buckets and disposed off.
Without the performance hit of fully automatic GC.
> Risking memory leaks is crazy when it's not something the customer is demanding.
Memory leaks have NEVER been a significant source of bugs.
Memory corruption has always been the problem (lack of memory safety, ie. operating in perpetual unsafe block), not the memory leaks.
Memory leaks are relatively trivial to track and account for in comparison.
Arenas avoid most of the performance problems of malloc/free.
I think the bigger problem with arenas and manual management is memory lifetime is very hard to get right, particularly in the context of concurrent operations. It also cuts away algorithms you can do.
Random forced pauses are the only problem that comes from GC, otherwise it's great for throughput and just a nice feature, as a sibling comment says. No GC languages do not make code magically faster, they still have malloc/free. However, GC is surrendering control over when a program may be paused.
Keep in mind a large portion of time NativeAOT is actually SLOWER than going through RyuJIT with the only definitive benefit being smaller binaries, and it's not like you can't do Span<T> and ref structs in modern C# for manual low level memory control already.
So my question is just... why?
https://migeel.sk/blog/2023/12/08/building-bare-metal-bootab...
I would not want to build a long term project on top of this, as maintaining a fork of the .NET runtime is somewhat labor intensive.
Nice POC, especially on MS-DOS but nothing truly relevant in the long run, I’m afraid
I commented this one explicitly because that zero c# platform pitched here is just the language syntax you know and then manual new/delete just like in c++
Thanks. This made me smile. Remember Mike Acton worked on Unity for a while. Look him up. See if he doesn’t care about memory. (I am not Mike).
That said, I don't see how this project fits in all that nicely.
I have not yet tested out Beef, but it seems to be more in line with what you'd want from a native C#-like language.