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# typeC++ aliasUnderlying type
sbyteSharpRuntime::sbytecsint8_t
byteSharpRuntime::bytecsuint8_t
shortSharpRuntime::shortcsint16_t
ushortSharpRuntime::ushortcsuint16_t
intSharpRuntime::intcsint32_t
uintSharpRuntime::uintcsuint32_t
longSharpRuntime::longcsint64_t
ulongSharpRuntime::ulongcsuint64_t
charSharpRuntime::charcschar16_t
floatfloatfloat (native)
doubledoubledouble (native)
boolboolbool (native)
stringstd::stringstd::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 areaComponent targetPhysical owner
Core object model, primitives, String, ArraySharpRuntime::Core.Basemodules/core
CollectionsSharpRuntime::Collections.Coremodules/collections
TasksSharpRuntime::Threading.Tasksmodules/threading-tasks
JSONSharpRuntime::Text.Jsonmodules/text-json
CompressionSharpRuntime::IO.Compressionmodules/io-compression
WebSocketsSharpRuntime::Net.WebSocketsmodules/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# ConceptC++ Representation
stringstd::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>)
ActionSystem::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:

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.