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

     

  • 相关阅读:
    第四章 高级查询(二)
    部分 语法Mysql
    MySQL高级查询
    BZOJ 3124 SDOI2013 直径
    BZOJ 3130 SDOI2013 费用流
    BZOJ 3993 SDOI2015 星际战争
    BZOJ 3997 TJOI2015 组合数学
    BZOJ 4003 JLOI2015 城池攻占
    BZOJ 3925 ZJOI2015 地震后的幻想乡
    codeforces #313 div1 E
  • 原文地址:https://www.cnblogs.com/FsharpZack/p/2764029.html
Copyright © 2011-2022 走看看