zoukankan      html  css  js  c++  java
  • F#修改给定内存地址空间中的值

    对于F#程序员来说,修改特定内存地址空间的值并不是一件很常见的事,和C#一样,F#代码由F#编译器编译之后生产托管模块,但是F#中并没有提供C#中的unsafe功能,那么如何在F#中修改给定内存地址空间的值呢,下面的这些代码就可实现此要求:

    //Memory Address,you may get this address from some other operations
    //not sure if this is readable safe address
    let p = 0x002100000n
    
    //Pointer to the Address
    let address : nativeptr<int32> = Microsoft.FSharp.NativeInterop.NativePtr.ofNativeInt(p)
    
    //set the value which is stored in the memory with given address and offset to 0xA
    let setV = Microsoft.FSharp.NativeInterop.NativePtr.set(address) 0 0xA
    
    //get the changed value
    let result = Microsoft.FSharp.NativeInterop.NativePtr.read(address)

    这里的p为一nativeint类型数据,当然,在实际程序中我们不会明显的给出一个地址,也不方便给出,这里只是做个例子:)

    主要用到的function都是Microsoft.FSharp.NativeInterop.NativePtr命名空间的。有想法的话,可以尝试一下~:)

     

  • 相关阅读:
    散列
    AVL树的单旋与双旋
    Ubuntu系统目录
    os x文件系统结构简介
    c语言静态局部变量
    创建J2EE 5.0工程后,JSTL不能使用解决方法
    mysql
    指针
    servlet 访问项目
    c数组
  • 原文地址:https://www.cnblogs.com/FsharpZack/p/2764029.html
Copyright © 2011-2022 走看看