阅读映射视图访问内存映射文件或存储的全部内容,而不知道它的大小 [英] Read all contents of memory mapped file or Memory Mapped View Accessor without knowing the size of it
问题描述
我需要类似ReadToEnd或ReadAllBytes读取所有的使用MappedViewAccessor的MemoryMappedFile的内容,如果我不知道它的大小事情,我该怎么办呢?
I need something similar to ReadToEnd or ReadAllBytes to read all of the contents of the MemoryMappedFile using the MappedViewAccessor if I don't know the size of it, how can I do it?
我已经寻找它,我已经看到了这个问题,但它不是我要找的东西:
I have searched for it, I have seen this question, but it is not the thing I am looking for:
<一个href="http://stackoverflow.com/questions/7956167/how-can-i-quickly-read-bytes-from-a-memory-mapped-file-in-net">How我可以快速读取从内存映射文件的字节在.NET?
编辑:
还有一个问题,(INT)stream.Length不给我正确的长度,它,而给使用的内部缓冲区的大小!我需要刷新这个问题,因为它是非常pressing。
There is a problem, the (int)stream.Length is not giving me the correct length, it rather gives the size of the internal buffer used! I need to refresh this question because it is very pressing.
推荐答案
而使用流:
public static Byte[] ReadMMFAllBytes(string fileName)
{
using (var mmf = MemoryMappedFile.OpenExisting(fileName))
{
using (var stream = mmf.CreateViewStream())
{
using (BinaryReader binReader = new BinaryReader(stream))
{
return binReader.ReadBytes((int)stream.Length);
}
}
}
}
这篇关于阅读映射视图访问内存映射文件或存储的全部内容,而不知道它的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!