We help IT Professionals succeed at work.

Memory Mapped File

jaxrpc
jaxrpc asked
on
Medium Priority
390 Views
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?

thanks
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008
Commented:
Memory Mapped Files
http://www.ecst.csuchico.edu/~beej/guide/ipc/mmap.html

<Quote>
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.
</Quote>

Resources for .NET implementations:

Using Memory Mapped Files in ASP.NET using VB.NET
http://www.codeproject.com/aspnet/VbNetMemoryMappedCache.asp

A .NET Memory-Mapped Cache TcpListener Service
http://www.eggheadcafe.com/articles/20050116.asp

Something to think about:

The Hidden Costs of Memory Mapped Files
http://blogs.borland.com/dcc/archive/2004/03/19/2380.aspx

<Quote>
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.
</Quote>


Bob

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.