wit-bindgen icon indicating copy to clipboard operation
wit-bindgen copied to clipboard

c# explore using readonly/span of memory for exports

Open jsturtevant opened this issue 1 year ago • 0 comments

          In the exports, we generate
public interface ITest {
    static abstract void EmptyListParam(byte[] a);
}

but we probably generate

public interface ITest {
    static abstract void EmptyListParam(ReadOnlySpan<byte> a)
}

because we don't expect the callee to modify that memory space.

This would allow us to pass the host buffer, instead of making a managed copy on the heap (and GC it later).

Note they could always make copy themself.

    public static void EmptyListParam(ReadOnlySpan<byte> a) {
        byte[] copy = a.ToArray();
    }

Originally posted by @pavelsavara in https://github.com/bytecodealliance/wit-bindgen/issues/1138#issuecomment-2625033304

jsturtevant avatar Jan 30 '25 21:01 jsturtevant