Get the memory address of Array in F#

本文介绍如何在F#编程语言中获取数组特定元素的内存地址。通过使用System.Runtime.InteropServices.Marshal类的方法UnsafeAddrOfPinnedArrayElement,可以得到指定数组元素的原生指针,并进一步将其转换为intptr类型。

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())

 

转载于:https://www.cnblogs.com/FsharpZack/archive/2012/11/07/2758805.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值