System.Span 的构造函数采用 int 长度,并且该长度在内部存储为 32 位值。
但是,默认填充无论如何都会使结构的大小为 16 字节,因此 32 位长度不会节省任何空间。
https://github.com/dotnet/corefx/blob/master/src/Common/src/CoreLib/System/Span.Fast.cs
Span的设计文档没有提到这一点。 https://github.com/dotnet/corefxlab/blob/master/docs/specs/span.md
从f#我试图使用成员约束在C#定义的对象上调用函数.由于c#成员函数接受多个参数,因此f#编译器将其视为元组,但在应用泛型成员约束时,我得到一个错误,该函数接受4个参数,但我只提供了一个.
我已经尝试从参数中形成元组或只是采用预先设置的参数集,但两者都给出了相同的错误.我想我必须错误地定义我的成员约束,但是没有很多带有多个参数的成员约束的例子.
let inline wrapForDecode (buffer:DirectBuffer) (offset:int) (blockLen:uint16) (version:uint16) : ^a =
let msg = new ^a()
(^a : (member WrapForDecode : (DirectBuffer*int*int*int)->unit) msg, (buffer, offset, (int blockLen), (int version)))
msg
let inline wrapForDecode2 (args :DirectBuffer*int*int*int) : ^a =
let msg = new ^a()
(^a : (member WrapForDecode : (DirectBuffer*int*int*int)->unit) (msg, args))
msg
Run Code Online (Sandbox Code Playgroud)
原始的WrapForDecode成员函数在c#中定义如下:
public void WrapForDecode(DirectBuffer buffer, int offset, int actingBlockLength, int actingVersion) {...}
Run Code Online (Sandbox Code Playgroud)
当我尝试调用该函数时,我得到了wrapForDecode或wrapForDecode2的以下错误.
The member or object constructor 'WrapForDecode' takes 4 argument(s) but is here given 1. …Run Code Online (Sandbox Code Playgroud)