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命名空间的。有想法的话,可以尝试一下~:)

     

  • 相关阅读:
    谜题48:我所得到的都是静态的
    谜题47:啊呀!我的猫变成狗了
    谜题46:令人混淆的构造器案例
    谜题45:令人疲惫不堪的测验
    谜题44:切掉类
    Python--csv文件处理
    Python装饰器
    Python单例模式
    <<Senium2自动化测试>>读书笔记二
    python之内置函数
  • 原文地址:https://www.cnblogs.com/FsharpZack/p/2764029.html
Copyright © 2011-2022 走看看