MemoryMappedFile语法问题 [英] MemoryMappedFile syntax issue

查看:81
本文介绍了MemoryMappedFile语法问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用MemoryMappedFile一次读取一个文件,进行分析和更改,然后写出一个新文件。 VS语法检查器一直拒绝读取和写入规范。这就是我所拥有的:



Trying to use MemoryMappedFile to read a file a piece at a time, analyze and change, then write out a new file. The VS syntax checker keeps rejecting the "Read" and "Write" specification. Here's what I have:

MemoryMappedFile mInputFile = MemoryMappedFile.CreateOrOpen(fileToRead, fInputSize,Read);
MemoryMappedFile mOutputFile = MemoryMappedFile.CreateOrOpen(fileToWrite, fInputSize,Write);
int sliceSize = 65536;
using (var mInputAccessor = mInputFile.CreateViewAccessor(0, fInputSize))
{
   byte[] sliceArray = new byte[sliceSize];
   using (var mOutputAccessor = mOutputFile.CreateViewAccessor(0, fInputSize))
   {
      for (long i=0;i< fInputSize;i+=sliceSize)
      {
         mInputAccessor.ReadArray(i, sliceArray, 0, sliceSize);
            
             <<<do some="" processing="" here="">>>

         mOutputAccessor.WriteArray(i, sliceArray, 0, sliceSize);
       }
    }
}</do>

推荐答案

我能看到的第一个错误是:你的最后一个参数 MemoryMappedFile.CreateOrOpen 调用应该是 System.IO.MemoryMappedFiles.MemoryMappedFileAccess.Read 系统.IO.MemoryMappedFiles.MemoryMappedFileAccess.Write

https://msdn.microsoft.com/en-us/library/dd267576%28v=vs.110%29.aspx [ ^ ],

https://msdn.microsoft.com/ EN-US /库/ system.io.memorymappedfiles.memorymappedfileaccess%28V = vs.110%29.aspx [ ^ ]。



类型名称的命名空间部分, System.IO.MemoryMappedFiles.MemoryMappedFileAccess 可以使用移动到



看,问题也是这样的不重要的;它只是理解C#非常基本的语法和语义以及以直接的方式使用FCL文档的能力。没有MemoryMappedFile语法这样的东西,它是关于非常基本的语言语法和对类型名称和命名空间等基本事物的理解。如果没有正确学习语言和平台,我不确定您是否可以进行高级I / O编程;在我学习语言之前,我个人甚至都不会尝试。



-SA
The first bug I can see is: last parameter of your MemoryMappedFile.CreateOrOpen call is supposed to be System.IO.MemoryMappedFiles.MemoryMappedFileAccess.Read and System.IO.MemoryMappedFiles.MemoryMappedFileAccess.Write:
https://msdn.microsoft.com/en-us/library/dd267576%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.io.memorymappedfiles.memorymappedfileaccess%28v=vs.110%29.aspx[^].

The namespace part of the type name, "System.IO.MemoryMappedFiles.MemoryMappedFileAccess" can be moved to "using".

Look, the problem is way too trivial; it's just about understanding C# very basic syntax and semantic and the ability to use the FCL documentation in a straightforward way. There is no such thing as "MemoryMappedFile syntax", it's about very basic language syntax and understanding of such basic things as type names and namespaces. I'm not sure you can advanced I/O programming without learning the language and platform properly; I personally would not even try before I learn the language.

—SA


谢谢解决方案和社论。自1968年以来,我至少在10个不同的平台上使用高级I / O编程。除了重新发明20年前解决的问题的解决方案之外,我不确定微软是否已经提升了最新技术水平。



添加层和层次的钝语法除了创建一支专家大军之外,还有20次覆盖的召唤几乎无法推进现有技术水平,因为他们需要深入研究才能理解非常简单的事情。
Thanks for the solution and the editorial. I have been working with "advanced I/O programming" since 1968 on at least 10 different platforms. Aside from re-inventing solutions to problems solved 20 years ago I'm not sure Microsoft has advanced the state of the art much.

Adding layers and layers of obtuse syntax and calls with 20 overrides does little to advance the state of the art except to create an army of "experts" who live for esoteric coding techniques that require lengthy study to understand very simple things.


这篇关于MemoryMappedFile语法问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆