MemoryMappedFile doesn't work with 2 processes?

前端 未结 2 1940
生来不讨喜
生来不讨喜 2020-12-18 13:58

I\'ve made a simple test with a MemoryMappedFile as msdn says :

2 processes, 1 memory mapped file :

  • the first process adds the string \"1
2条回答
  •  天命终不由人
    2020-12-18 14:45

    EDIT

    I noticed one apparently strange thing in the code of ProcessB. This code

    using (MemoryMappedViewStream stream = mmf.CreateViewStream(1, 0))
    

    creates a view from the first byte, but the strings in .NET are 2 bytes. I think it should be enough to you to make that 1->2 become 2. So the offset of the ProcessB view from the start of the mapped file will be after already inserted "1" string from ProcessA.

    In your case seems that you overlap them.

    Hope this helps.

提交回复
热议问题