3 ms·
> I'd be surprised if this works in practice because the String processing in C# is surely going to keep making Heap objects ? The new Span<T>, specifically Sp
by briHass 5y ago
> I'd be surprised if this works in practice because the String processing in C# is surely going to keep making Heap objects ?
The new Span<T>, specifically Span<char>, stuff allows you to slice and read strings without creating new objects, and string has both a c-tor for a (readonly) span and a Create method that takes a delegate that allows you to fill the string already allocated on the heap.
- tialaramex 5y agoI didn't know about Span<T>, but it makes sense to give C# slices somehow. However so far as I've seen while writing C# popular APIs want an actual String and they won't take these slices as a substitute? The ergonomics seem poor. Maybe I'm mistaken and magically my C# code which says "string" everywhere is actually converted at runtime to use Span<char> and go real fast? But it doesn't look like it. The Rust APIs really do take the slice reference &str, it's just normal in Rust to say &str unless you very specifically want a mutable String for some reason (e.g. you're going to insert stuff into it)