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

     

  • 相关阅读:
    promethus监控JVM jar包
    ubuntu中文乱码解决办法
    IT焦躁中的赤子青年
    ftp neo4j http kafka搭建
    查看python脚本执行过程
    解决coredns-7f9c544f75-2sjs2一直处于ContainerCreating
    番茄工作法
    数据库的性能优化
    MyBatis
    CentOS下安装JDK,Tomcat,Redis,Mysql,及项目发布
  • 原文地址:https://www.cnblogs.com/FsharpZack/p/2764029.html
Copyright © 2011-2022 走看看