Quantcast
Viewing all articles
Browse latest Browse all 8901

Span を DllImport に渡す

// c の定義SAMPLE_EXPORTvoidSAMPLE_NumberSequence(unsignedchar*bytes,intlength);
[DllImport(DllName,EntryPoint="SAMPLE_NumberSequence")]publicstaticexternvoidSAMPLE_NumberSequence_UseRef(refbytebytes,intlength);

と書いておいて

staticvoidStackSample(){Span<byte>span=stackallocbyte[10];SampleImport.SAMPLE_NumberSequence_UseRef(refspan[0],span.Length);Console.WriteLine(ToString(span));}

ref span[0]で先頭要素へのリファレンスを渡すことでできた。

実験コード

https://github.com/ousttrue/SpanSample


Viewing all articles
Browse latest Browse all 8901

Trending Articles