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# 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 |
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>, <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.