Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Show HN: Zero C# – C# without a runtime or GC

Article URL: https://onurgumus.github.io/zero-csharp/index.html Comments URL: https://news.ycombinator.com/item?id=50590279 Points: 172 # Comments: 120

In a groundbreaking development, a fork of bflat enables the compilation of C# code into standalone native programs, eliminating the need for a .NET runtime or garbage collector. This innovative approach maintains C#'s familiar syntax, type checking, and generics, while providing memory management through arenas that can be freed all at once.

The same source code can run across multiple platforms, including Linux, macOS, Windows, WebAssembly, and DOS on a 386 processor. Notably, the compiler retains all the stringent memory safety checks found in the .NET framework.

The zero C# implementation offers several advantages over traditional C# programs. For instance, it doesn't require any runtime or additional libraries to be installed, as it uses the native C library on macOS, a container on the same platform, or the system C library on Windows. It can even be compiled directly on a Mac using the Mac's own clang compiler. Furthermore, the program can be executed under the WebAssembly system interface (WASI) using the NativeAOT-LLVM tool, allowing it to run within the wasmtime runtime.

Memory management is handled differently in this native C# implementation. Instead of using a garbage collector, the system employs arenas for memory allocation, and all memory is released at once when a lifetime ends. The I/O operations are streamlined, with input and output handled directly into output and input buffers, respectively.

Strings that are expected to persist are stored in the arena, and custom collections like List and Dictionary, along with their reference and string key variants, are also implemented as handles to the arena.

Adopting this zero C# approach involves a few adjustments, as outlined in the provided documentation. Each platform-specific guide explains the changes required and offers solutions to potential challenges. The memory safety rules have been updated to ensure that pointers are always safe to create, and reading through a pointer is explicitly marked and explained.

To help newcomers, the resource includes four pages that guide users from a complete beginner to an interactive program, all using the same compilation process supported by FreeDOS and various emulators. For those seeking specific information, the task guides answer targeted questions, while the reference section lists every type available in the library.

Rewritten by urgent.news; may contain errors — check the original.

Source: onurgumus.github.io

Read the original at onurgumus.github.io →

Report a problem with this story

More in Tech

Large log records in Dynatrace: limits, native support and best practices

A ticket lands: « the partner call is cut off halfway through in the logs ». You open the record and it simply stops. The payload crossed a limit somewhere.

  • Default log entry body limit is 10 MB for Grail path, 512 kB for Classic pipeline
  • API requests limited to 10 MB, batch over 16 MB after preprocessing results in HTTP 413 error
  • OpenPipeline expands record size limit to 16 MB, 50,000 attributes per log with 32 kB cap

More from Saturday 21 November →