mir.net
July 14, 2023 · View on GitHub
.NET Implementation of Mir Ref-Counted Type System (MTS)
Features
- Fast generic types that are easy to construct, use, and pass between managed and unmanaged code.
- Faster than Protocol Buffers as well as any other serialization library because it is completely zero-copy.
- Requires around half the user code compared to Protocol Buffers.
- D and C++ implementations are provided via Mir Algorithm
- D, C++, and C# MTS implementations are self-contained. C# implementation requires neither Mir Algorithm nor D/C/C++ runtimes.
- Hands-free. Just construct, pass, and forget. Mir objects hold all required information to destroy them and free memory.
The library is used in a large private codebase.
Install with NuGet
Or build NuGet package your self.
cd Mir
dotnet pack --configuration Release
Basic Types
- Array
- Array slices
- Matrices
- Sorted dictionaries (
Series) - Slim shared pointers
- Shared Pointers with inheritance
- POD small strings
Composed user-defined types
Mir types can be composed using other Mir types and C# POD types that don't require special marshaling. MirWrapper is a base class for all non-POD library and user-defined Mir types. It requires the structure payload (Impl) to be defined.
MirPtr and MirSlimPtr can be used to wrap a native type without defining its structure payload in C#.
Table of correspondence
(check the source repository if the table isn't rendered correctly because of the nuget issue)
| D Type | C# Type | C++ Type |
|---|---|---|
| SlimRCPtr!Type | MirSlimPtr<Type> | mir_slim_rcptr<Type> |
| RCPtr!Type | MirPtr<Type> | mir_rcptr<Type> |
| RCArray!Type | `MirArray<Type, @>$ \times 2 | $mir_rcarray |
| Slice!(RCI!Type) | `Slice | $mir_slice<mir_rci |
| Slice!(RCI!Type, 2) | `Matrix | $mir_slice<mir_rci |
| Slice!(Type*) | `SliceView<Type, @>$ \times 2 | $mir_slice<Type*>` |
| Series!(RCI!Key, RCI!Value) | `Series<Key, Value, @>$ \times 2 | $mir_series<mir_rci |
| SmallString!N | SmallStringN, N=4,31,32,64,128 | mir::SmallString<N> |
| Series!(RCI!(RCArray!(const char)), RCI!Value) | StringSeries<Value> | mir_series<mir_rci<mir_rcarray<const char>>, mir_rci<Value>> |
Name<... , @>$ \times 2 - \text{means} \text{a} \text{type} \text{has} \text{two} \text{declarations}, $Name<... > and Name<... , Impl>, where Impl
is an unmanaged C# handle structure that describes non-POD Mir Type.
Composed Mir Type (CMT) is a type that is composed of CMT fields, library RefCounted fields, and POD structures and types.
Unmanaged C# handles should use byte instead of bool.