2024年1月31日发(作者:)
}}}public struct MyColor{public short Red;public short Green;public short Blue;public short Alpha;// Make the view void Brighten(short value){Red = (short)(ue, (int)Red + value);Green = (short)(ue, (int)Green + value);Blue = (short)(ue, (int)Blue + value);Alpha = (short)(ue, (int)Alpha + value);}}Imports rts MappedFilesImports pServicesClass ProgramSub Main()Dim offset As Long = &H10000000 ' 256 megabytesDim length As Long = &H20000000 ' 512 megabytes' Create the memory-mapped mmf = FromFile("c:", , "ImgA")' Create a random access view, from the 256th megabyte (the offset)' to the 768th megabyte (the offset plus length).Using accessor = ViewAccessor(offset, length)Dim colorSize As Integer = (GetType(MyColor))Dim color As MyColorDim i As Long = 0' Make changes to the While (i < length)
using (var accessor = ViewAccessor(4000000, 2000000)){int colorSize = (typeof(MyColor));MyColor color;// Make changes to the (long i = 0; i < 1500000; i += colorSize){(i, out color);en(20);(i, ref color);}}}}}public struct MyColor{public short Red;public short Green;public short Blue;public short Alpha;// Make the view void Brighten(short value){Red = (short)(ue, (int)Red + value);Green = (short)(ue, (int)Green + value);Blue = (short)(ue, (int)Blue + value);Alpha = (short)(ue, (int)Alpha + value);}}Imports MappedFilesImports pServicesClass ProgramPublic Shared Sub Main(ByVal args As String())' Assumes another process has created the memory-mapped file.
}eMutex();ine("Start Process B and press ENTER to continue.");ne();ine("Start Process C and press ENTER to continue.");ne();e();using (MemoryMappedViewStream stream = ViewStream()){BinaryReader reader = new BinaryReader(stream);ine("Process A says: {0}", olean());ine("Process B says: {0}", olean());ine("Process C says: {0}", olean());}eMutex();}}}Imports rts MappedFilesImports ingModule Module1' Process A:Sub Main()Using mmf As MemoryMappedFile = New("testmap", 10000)Dim mutexCreated As BooleanDim mTex As Mutex = New Mutex(True, "testmapmutex", mutexCreated)Using Stream As MemoryMappedViewStream = ViewStream()Dim writer As BinaryWriter = New BinaryWriter(Stream)(1)End eMutex()ine("Start Process B and press ENTER to continue.")ne()ine("Start Process C and press ENTER to continue.")
ne()e()Using Stream As MemoryMappedViewStream = ViewStream()Dim reader As BinaryReader = New BinaryReader(Stream)ine("Process A says: {0}", olean())ine("Process B says: {0}", olean())ine("Process C says: {0}", olean())End eMutex()End UsingEnd SubEnd ModuleProcess Busing System;using ;using MappedFiles;using ing;class Program{// Process B:static void Main(string[] args){try{using (MemoryMappedFile mmf = isting("testmap")){Mutex mutex = isting("testmapmutex");e();using (MemoryMappedViewStream stream = ViewStream(1, 0)){BinaryWriter writer = new BinaryWriter(stream);(0);}eMutex();
}}catch (FileNotFoundException){ine("Memory-mapped file does not exist. Run Process A first.");}}}Imports rts MappedFilesImports ingModule Module1' Process B:Sub Main()TryUsing mmf As MemoryMappedFile = isting("testmap")Dim mTex As Mutex = isting("testmapmutex")e()Using Stream As MemoryMappedViewStream = ViewStream(1, 0)Dim writer As BinaryWriter = New BinaryWriter(Stream)(0)End eMutex()End UsingCatch noFile As ine("Memory-mapped file does not exist. Run Process A first." & vbCrLf & e)End TryEnd SubEnd ModuleProcess Cusing System;using ;using MappedFiles;using ing;class Program
{// Process C:static void Main(string[] args){try{using (MemoryMappedFile mmf = isting("testmap")){Mutex mutex = isting("testmapmutex");e();using (MemoryMappedViewStream stream = ViewStream(2, 0)){BinaryWriter writer = new BinaryWriter(stream);(1);}eMutex();}}catch (FileNotFoundException){ine("Memory-mapped file does not exist. Run Process A first, then B.");}}}Imports rts MappedFilesImports ingModule Module1' Process C:Sub Main()TryUsing mmf As MemoryMappedFile = isting("testmap")Dim mTex As Mutex = isting("testmapmutex")e()Using Stream As MemoryMappedViewStream = ViewStream(2, 0)
Dim writer As BinaryWriter = New BinaryWriter(Stream)(1)End eMutex()End UsingCatch noFile As ine("Memory-mapped file does not exist. Run Process A first, then B." & vbCrLf & e)End TryEnd SubEnd Module请参阅


发布评论