f# – MemoryMappedFiles.MemoryMappedFile.CreateFromFile不会
在
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() 错误信息
单声道版本: [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) 编辑:似乎内存映射的不同底层行为在API中公开,因此您需要将文件自己扩展到正确的长度以进行平台中立 let f = File.Open(path,FileMode.Append,FileAccess.Write) let pad = l- FileInfo(path).Length let padding = Array.create (int32 pad) 0uy f.Write(padding,int pad) f.Close() 解决方法
查看CreateFromFile的.NET实现,没有该功能的实现.除了参数检查之外,从我可以看出,它是Windows API调用的一个纤薄的包装器.
由于这个原因,创建一个更大的文件的能力更像是.NET领域的巧合,因此如果底层操作系统不允许类似的功能,Mono就会删除这种能力也就不足为奇了. 更简单,不太可能,因为.NET版本在技术上也没有扩展文件,Windows API也是如此. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |