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.

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:

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

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>, <condition_variable>. Provides .NET-like wrappers. No async/await. 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 links against libSHARP_RUNTIME.a and uses all of its System::* types. See CNA Integration.