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 @ 2012-11-07 14:36  ZackZhou  阅读(212)  评论(0编辑  收藏  举报