How to pin a generic Span<T> instance to work on it with Parallel.For?
I'm rewriting some of my extension methods using the new Span<T> type and I'm having trouble finding a way to properly pin a generic instance to be able to use parallel code to work on it. As an example, consider this extension method: public static unsafe void Fill<T>(this Span<T> span, [NotNull] Func<T> provider) where T : struct { int cores = Environment.ProcessorCount, batch = span.Length / cores, mod = span.Length % cores, sizeT = Unsafe.SizeOf<T>(); //fixed (void* p0 = &span.DangerousGetPinnableReference()) // This doesn't work, can't pin a T object void* p0 = Unsafe.AsPointer(ref span