Get the memory address of Array in F#

It's not convenient to get the memory address of object in F#, and the following code will illustrate how to get the memory of given index item of an array:

//Define your array
let arr = [|1;23|]
//Get the nativeint of arr.[0]
let nativeint = System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement(arr,0)
//Construct a intptr using the nativeptr<unit> 
let intptr = new System.IntPtr(nativeint.ToPointer())

 

posted @   ZackZhou  阅读(215)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示