Enlargening MemorymappedFiles RRS feed

  • Question

  • Hi ,,

    Working with MMFs, I have initially created a MMF of, say 600 bytes. This works fine. The MMF can subsequently be read and written to. However, when once created, I try to write to it, with a much larger buffer , say 400000 bytes, I get an unauthorizedaccessexception (access to path denied) on the createviewaccessor. Playing around with this, I have detected, that the exception occurs, when (a) the attempt createviewaccessor is much larger, and (b) you pass a 4k boundary.

    My question:

    How do I get around this ?? I have tried creating a new MMF, but get the message that It already exists. I can find no means of deleting an already existing MMF, or making it larger. How to proceed ????

    thx ... Steve

    Monday, November 2, 2015 8:13 AM


  • The MemoryMappedFile object is disposable, hence to 'delete' it (which may or may not remove the underlying file depending on whether you created it persistent or not), you simply call the Dispose() method.

    Or better still, use it within a 'Using' statement as with the example here.

    I do not think you can simply enlarge an already created file.

    You are much better of using a file that is big enough to begin with if possible - if you use a non-persisted file and access via MemoryMappedViewAccessor then resources are not used until required. (I'm not taking credit for this answer - I found it here!)

    Monday, November 2, 2015 10:22 AM