Hacker News new | ask | show | jobs
by MaulingMonkey 1854 days ago
Technically, but they tend to be much harder to hack on.

It's trivial to replace malloc/free with my_malloc/my_free - and integrating libraries that replace malloc/free as-is without renaming also tends to be straightforward. In C++, you can overload new/delete to use my_* with little hassle, or placement new to instantiate classes on previously allocated memory directly.

Meanwhile, C# and Java provide absolutely no means of creating instances of their classes via anything other than their built-in GCs. You can't just distribute a .exe or .jar with a replaced GC - instead, you need to create/distribute/install an entirely new runtime, and even that doesn't really provide any sane means of having multiple GCs living side by side. This is all theoretically technically possible, but orders of magnitude more work.

1 comments

C# has structs and support for native heap management, and as of C# 9 very few features missing versus something like Modula-3 or even D.

You can provide your own GC on .NET via the COM API.

https://github.com/Potapy4/dotnet-coreclr/blob/master/Docume...

Just like Java since version 10, https://medium.com/@unmeshvjoshi/writing-your-own-garbage-co...

> C# has structs

And yet so little code uses them that to eschew the builtin GC is to eschew basically the entire .NET framework. Even basic foreach loops go through IEnumerable interfaces - theoretically boxing even structs. They also come with different semantics - sometimes terrfiyingly subtly differences when combined with properties.

> and support for native heap management

IDisposable and friends are awkward fill-ins for proper RAII tools for native heaps.

That said, these options can be incrementally deployed in your existing codebase without resorting to another language, so they're more accessible options

> [links]

Hooking/replacing the GC seems more straightforward these days, than when I last looked into it though! Although, coreclr APIs won't help with Unity, or Mono. OpenJDK is at least used by modern Android these days, so perhaps there's a way to use it's GC customization options...?

Some developers know their stuff,

https://devblogs.microsoft.com/aspnet/grpc-performance-impro...

Others are doomed never to move away from new.