How to dynamically expand a Memory Mapped File

后端 未结 5 1936
星月不相逢
星月不相逢 2020-12-09 08:16

I\'ve used C# to solve the following requirement.. - create an app the can receive a lot of data fast - you must be able to analyse the received data while more are incoming

5条回答
  •  半阙折子戏
    2020-12-09 08:36

    The reason that the code does not compile is because it uses a non-existing overload. Either create a filestream yourself and pass it to the correct overload (assuming 2000 will be your new size):

    FileStream fs = new FileStream("C:\MyFile.dat", FileMode.Open);
    MemoryMappedFile mmf = MemoryMappedFile.CreateFromFile(fs, "someName", 2000,
     MemoryMappedFileAccess.ReadWriteExecute, null, HandleInheritablity.None, false);
    

    Or use this overload to skip the filstream creation:

    MemoryMappedFile mmf = MemoryMappedFile.CreateFromFile("C:\MyFile.dat", 
              FileMode.Open, "someName", 2000);
    

提交回复
热议问题