F# 声明本地PTR<;单位>;类型

F# 声明本地PTR<;单位>;类型,f#,interop,native,c#-to-f#,unit-type,F#,Interop,Native,C# To F#,Unit Type,我想知道是否可以在F#中声明类型: nativeptr<unit> 然后我从一个类成员处调用以下代码: let dst = //get nativeint destination address let src = //get nativeint source address let bd = createBlitDelegate<'T>() let tdst = NativePtr.ofNativeInt<'T> dst let tsrc = Nati

我想知道是否可以在F#中声明类型:

nativeptr<unit>
然后我从一个类成员处调用以下代码:

let dst = //get nativeint destination address
let src = //get nativeint source address

let bd = createBlitDelegate<'T>()

let tdst = NativePtr.ofNativeInt<'T> dst
let tsrc = NativePtr.ofNativeInt<'T> src

do blit bd tdst tsrc (uint32 size)
//Program.MemCpy.Invoke(dst.ToPointer(), dst.ToPointer(), uint32 size)

根据您的描述,我不清楚您为什么想要
nativeptr
。本质上,
nativeptrYes,这确实是个问题。非常感谢。另一个提示:如果您希望IL
cpblk
指令在使用(例如)
TDerived[]
数组源到
TBase[]
目标时支持托管指针上的标准.NET数组协方差,那么您必须创建具有所谓“受控可变性”的源
ref
(仅限)将
操作码.Readonly
前缀放在
操作码.Ldelema
指令之前。否则,如果源数组的实际类型具有派生元素类型,您将崩溃,出现
ArrayTypeMismatchException
exception“试图以与数组不兼容的类型访问元素”异常。。。。用于(例如)协变复制一个
的IL!T
元素从
srcArr[ix]
!T&pDst
最终看起来是这样的:
ldarg-pDst;ldarg-srcArr;ldarg ix;只读。阿尔德勒马!Tsizeof!Tcpblk
let dst = //get nativeint destination address
let src = //get nativeint source address

let bd = createBlitDelegate<'T>()

let tdst = NativePtr.ofNativeInt<'T> dst
let tsrc = NativePtr.ofNativeInt<'T> src

do blit bd tdst tsrc (uint32 size)
//Program.MemCpy.Invoke(dst.ToPointer(), dst.ToPointer(), uint32 size)
type blitDelegate = delegate of nativeint * nativeint * uint32 -> unit