-
A software platform and runtime ecosystem for building and running applications, primarily using languages such as C#, F#, and Visual Basic.
-
It provides:
-
a runtime
-
core libraries
-
language tooling
-
a compilation pipeline
-
cross-platform support
-
-
The core execution component is the Common Language Runtime (CLR) .
-
Main responsibilities of the runtime include:
-
memory management (garbage collection)
-
JIT compilation
-
type safety
-
exception handling
-
threading
-
interop with native code
-
-
Execution pipeline:
C# source code
↓
C# compiler (Roslyn)
↓
Intermediate Language (IL)
↓
CLR JIT compiler
↓
Native machine code
CLR (Common Language Runtime)
-
The CLR is the runtime environment responsible for executing managed code.
-
Main features:
JIT Compilation
-
C# code compiles to IL (Intermediate Language) first.
-
Example IL:
ldloc.0
ldloc.1
add
stloc.2
-
At runtime the CLR converts IL into machine code using Just-In-Time compilation.
Garbage Collection
-
Automatic memory management.
-
The GC:
-
tracks allocated objects
-
determines unreachable objects
-
frees memory automatically
-
-
Heap structure typically uses generational GC:
-
Gen 0
-
short-lived objects
-
-
Gen 1
-
medium-lived
-
-
Gen 2
-
long-lived
-
-
-
Short-lived objects are collected more frequently.
Managed vs Unmanaged Code
-
Managed code:
-
executed under CLR control
-
memory handled by GC
-
-
Example:
class Player { int health; } -
Unmanaged code:
-
native code outside CLR control
-
typical examples: C/C++ libraries
-
-
Interop example:
[DllImport("kernel32.dll")] static extern void Sleep(int ms);
Mono
-
Mono is a cross-platform implementation of the Common Language Runtime (CLR) and the .NET Framework .
-
Makes the .NET Framework available in non-Windows environments.
-
Supports languages running on the CLR, such as C#, VB.NET, and F#.
-
Name:
-
The name was chosen by the original team as a pun since "mono" means "monkey" in Spanish, and there was a tradition of using animal-related names in the open-source community (like GNU and Python).
-
-
In Godot:
-
Godot Mono == Mono Framework support to run C# scripts.
-
Mono was the natural choice because:
-
It is open source and compatible with Godot's open distribution goals.
-
Offers .NET standard compatibility to run C#.
-
Works well on various operating systems, like Linux, macOS, and Windows.
-
-
It is a separate edition because adding Mono increases the Godot binary size, and not all users need it.
-
Common Type System (CTS)
-
Defines how all .NET languages represent types so they can interoperate.
-
All compile into the same runtime type system.
| C# type | CTS type |
| -------- | ---------------- |
|
int
|
System.Int32
|
|
string
|
System.String
|
|
bool
|
System.Boolean
|
-
So:
int a = 10; -
Is equivalent to:
System.Int32 a = 10;
Common Language Specification (CLS)
-
Defines a subset of CTS rules that all .NET languages must follow to ensure interoperability.
-
Example rule:
-
Some languages do not support unsigned integers.
-
Therefore CLS-compliant libraries should avoid exposing:
-
uint -
ulong
-
-
Public APIs usually follow CLS rules.
-