Runtime Overview
Core object model, type representation, memory model, and subsystem summaries.
Core Object Model
All non-primitive, non-template types in sharp-runtime derive from System::Object. This mirrors the .NET object hierarchy where every class ultimately derives from System.Object.
modules/core/include/System/Object.hpp (public include: System/Object.hpp)
class Object {
public:
virtual ~Object();
virtual std::string ToString() const;
virtual bool Equals(const Object* obj) const;
static bool Equals(const Object* objA, const Object* objB);
static bool ReferenceEquals(const Object* objA, const Object* objB);
virtual int GetHashCode() const;
virtual const std::string& GetTypeName() const = 0; // pure virtual
};
GetTypeName
Every concrete class must override GetTypeName(). Macros are provided to reduce boilerplate:
// In .hpp:
class MyClass : public System::Object {
GetTypeNameHPP() // expands to declaration
};
// In .cpp:
GetTypeNameCPP(MyClass, MyClass) // expands to implementation
Primitive Types
C# primitive types map to C++ type aliases in the SharpRuntime namespace:
modules/core/include/SharpRuntime/SharpRuntimeHelper.hpp (public include: SharpRuntime/SharpRuntimeHelper.hpp)
| C# type | C++ alias | Underlying type |
|---|---|---|
sbyte | SharpRuntime::sbytecs | int8_t |
byte | SharpRuntime::bytecs | uint8_t |
short | SharpRuntime::shortcs | int16_t |
ushort | SharpRuntime::ushortcs | uint16_t |
int | SharpRuntime::intcs | int32_t |
uint | SharpRuntime::uintcs | uint32_t |
long | SharpRuntime::longcs | int64_t |
ulong | SharpRuntime::ulongcs | uint64_t |
char | SharpRuntime::charcs | char16_t |
float | float | float (native) |
double | double | double (native) |
bool | bool | bool (native) |
string | std::string | std::string |
Component Boundaries
The runtime is physically split into 40 components. The public namespaces above are stable; their implementation is selected through CMake targets. A few representative mappings are:
| Public API area | Component target | Physical owner |
|---|---|---|
| Core object model, primitives, String, Array | SharpRuntime::Core.Base | modules/core |
| Collections | SharpRuntime::Collections.Core | modules/collections |
| Tasks | SharpRuntime::Threading.Tasks | modules/threading-tasks |
| JSON | SharpRuntime::Text.Json | modules/text-json |
| Compression | SharpRuntime::IO.Compression | modules/io-compression |
| WebSockets | SharpRuntime::Net.WebSockets | modules/net-websockets |
Link a direct target and let its public dependency closure propagate. Use SharpRuntime::All only when the complete surface is intended.
Type Representation Summary
| C# Concept | C++ Representation |
|---|---|
string | std::string |
T[] (array) | std::vector<T> |
List<T> | System::Collections::Generic::List<T> (wraps std::vector) |
Dictionary<K,V> | System::Collections::Generic::Dictionary<K,V> (wraps std::unordered_map) |
Nullable<T> | System::Nullable<T> (wraps std::optional<T>) |
Action | System::Action = std::function<void()> |
Action<T> | System::ActionT<T> = std::function<void(T)> |
Func<R> | System::Func<R> = std::function<R()> |
Predicate<T> | System::Predicate<T> = std::function<bool(T)> |
event EventHandler<T> | System::EventHandler<T> (combined delegate+event) |
Memory Ownership Model
No garbage collector. Memory is managed with C++ RAII:
- Stack-allocated for most value types
std::shared_ptr<T>for shared ownershipstd::unique_ptr<T>for exclusive ownership- Raw pointers for non-owning references only
See Memory Management for details.
String Implementation
Strings use std::string. System::String is a non-instantiable static utility class providing helpers like Split, Format, IsNullOrEmpty, StartsWith. See Strings.
Array Implementation
Arrays use std::vector<T>. System::Array is a static template class providing Sort, Copy, Resize, IndexOf, Reverse, Clear. See Arrays.
Exception System
System::Exception extends std::exception. Exceptions are real C++ exceptions. See Exceptions.
Delegate/Event System
Built on std::function. EventHandler<T> combines delegate type + subscriber list. See Delegates & Events.
Threading
Uses C++ <thread>, <mutex>, <atomic>, and <condition_variable>. It provides .NET-like wrappers, plus task and channel components. C# language-level async/await syntax does not exist in C++; see Threading.
I/O
Backed by C++ standard I/O, POSIX APIs (guarded), ZLIB for compression, miniz for ZIP. See I/O.
Relationship to CNA
CNA (C++ XNA 4.0 port) depends on sharp-runtime as its foundation layer. It selects the complete component surface through SharpRuntime::All and uses its System::* types. See CNA Integration.