小编Dar*_*ren的帖子

MemoryMappedFiles.MemoryMappedFile.CreateFromFile不会扩展linux/mono下的文件

在windows下,当容量参数(最后一个参数)设置为比底层文件大时,此F#代码将文件从12个字节扩展到655346个字节.这似乎是扩展内存映射文件最干净的方法.在mono/linux下,它抛出一个ArgumentException:capacity,除非该文件与映射的容量一样长.是否有一种干净的方式来获取单声道扩展文件,或者我必须先预先扩展文件才能映射?

let Main () =
    let path = "parts.pash"
    let l = 65536L
    let mm =    MemoryMappedFiles.MemoryMappedFile.CreateFromFile(path,FileMode.OpenOrCreate,"pashmap",l)

    ()

Main()
Run Code Online (Sandbox Code Playgroud)

错误信息

未处理的异常信息:System.ArgumentException:容量在System.IO.MemoryMappedFiles.MemoryMappedFile.CreateFromFile(System.String路径,的FileMode模式,System.String MAPNAME,Int64的容量,MemoryMappedFileAccess访问)[0x00000]中:在System.IO.MemoryMappedFiles 0 .MemoryMappedFile.CreateFromFile(System.String路径,的FileMode模式,System.String MAPNAME,Int64的容量)[0x00000]中:0在Program.Main()[0x00000]中:0为$ Program.main @()[0x00000在:0

单声道版本:

[daz@clowder pash]$ mono --version
Mono JIT compiler version 2.10.1 (tarball Mon Apr  4 10:40:52 PDT 2011)
Copyright (C) 2002-2011 Novell, Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  x86
        Disabled:      none
        Misc:          softdebug
        LLVM:          supported, not enabled.
        GC:            Included Boehm (with typed GC and Parallel Mark)
Run Code Online (Sandbox Code Playgroud)

编辑:似乎内存映射的不同底层行为在API中公开,因此您需要将文件自己扩展到正确的长度以进行平台中立

let f …
Run Code Online (Sandbox Code Playgroud)

mono f#

6
推荐指数
1
解决办法
749
查看次数

无法访问F#类中的Dispose方法

我在F#中创建了一个实现IDisposable接口的类.该类被正确清理,use关键字能够访问Dispose方法.我有第二个用例,我需要显式调用Dispose方法,我无法在下面的示例中.似乎在课堂上没有Dipose方法.

open System

type Foo() = class
    do
        ()

    interface IDisposable with
        member x.Dispose() =
            printfn "Disposing"

end

let test() =
    // This usage is ok, and correctly runs Dispose()
    use f = new Foo()


    let f2 = new Foo()
    // The Dispose method isn't available and this code is not valid
    // "The field , constructor or member Dispose is not defined."
    f2.Dispose()

test()
Run Code Online (Sandbox Code Playgroud)

f# dispose

6
推荐指数
1
解决办法
705
查看次数

标签 统计

f# ×2

dispose ×1

mono ×1