Memory Mapped File

Posted on 2006-04-01
Last Modified: 2010-08-05
Hi, could someone explain to me what is a Memory Mapped File? Its uses? How could it be done in .NET?

Question by:jaxrpc
    1 Comment
    LVL 96

    Accepted Solution

    Memory Mapped Files

    There comes a time when you want to read and write to and from files so that the information is shared between processes. Think of it this way: two processes both open the same file and both read and write from it, thus sharing the information. The problem is, sometimes it's a pain to do all those fseek()s and stuff to get around. Wouldn't it be easier if you could just map a section of the file to memory, and get a pointer to it? Then you could simply use pointer arithmetic to get (and set) data in the file.

    Well, this is exactly what a memory mapped file is. And it's really easy to use, too. A few simple calls, mixed with a few simple rules, and you're mapping like a mad-person.

    Resources for .NET implementations:

    Using Memory Mapped Files in ASP.NET using VB.NET

    A .NET Memory-Mapped Cache TcpListener Service

    Something to think about:

    The Hidden Costs of Memory Mapped Files

    Are memory mapped files (MMFs) always faster than normal file I/O techniques?

    Memory mapped files are not always faster than custom data loading
    algorithms. You have no control over how much of the MMF is kept in memory
    or for how long. This means that using an MMF may push other things out of
    RAM, such as code or data pages that you will need back "soon".

    Also, page faults are not free. A page fault can take a lot longer for the system to process than a simple file I/O call. The additional system overhead of using page faults is hidden by the fact that fault processing is performed in the system kernel on a different thread, not in your process.


    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Global Keyboard Hooks Blocked 4 38
    Help file 1 28
    Help with uploading excel file 2 26
    Explain Unit of Work pattern 2 29
    Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (…
    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now