Click here to Skip to main content
15,890,897 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
See more:
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:

C#
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>
Posted
Updated 8-Oct-15 8:51am
v3
Comments
Sergey Alexandrovich Kryukov 8-Oct-15 15:15pm    
In what line? (Of course it will reject </do> :-)
—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
 
Share this answer
 
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.
 
Share this answer
 
Comments
Richard Deeming 29-Oct-15 14:00pm    
Don't post comments as new solutions. Use the "Have a Question or Comment?" button under the solution you want to respond to.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900