Is there any way to pass Span<T>
s to a library function?
I have a library function with a fixed shape:
public delegate double Fun(double x, object o);
public static void Solve(Fun f, out double y, object o)
{
y = f(1.0, o); // all the irrelevant details of the algorithm omitted
}
I’d like to pass in a function which requires external parameters that are Span<T>
s held on the stack to avoid allocations, but Span<T>
s cannot be passed as a parameter due to boxing and unboxing, and cannot be used in a generic type, passed as a params
keyword, or stored in instance variables.
Is there any way to solve this problem?