2 ms·
I'm not sure if you could replicate System.String, because the oddity is happening at the metadata level - apart from special cases like String, .Net types must
by zamalek 10y ago
I'm not sure if you could replicate System.String, because the oddity is happening at the metadata level - apart from special cases like String, .Net types must be compile-time constant length (if I remember correctly).
However, at the instruction level you can do some pretty awesome stuff. This slice[1] library is able to verifiably and safely grab a slice of data out of any arbitrary structure by using a MSIL feature that was invented for C++/CLR. The call site[2] is not unsafe.
[1]: https://github.com/joeduffy/slice.net/blob/master/src/PtrUtils.il https://github.com/joeduffy/slice.net/blob/master/src/PtrUti...
[2]: https://github.com/joeduffy/slice.net/blob/master/src/Slice.cs#L56 https://github.com/joeduffy/slice.net/blob/master/src/Slice....
- matthewwarren 10y agoYeah the slice stuff is pretty nice, it's actually now being developed on the CoreFX Labs[1], so it might eventually make it into the Core CLR. [1]: https://github.com/dotnet/corefxlab/tree/master/src/System.Slices https://github.com/dotnet/corefxlab/tree/master/src/System.S...