Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 374
  • Last Modified:

Memory Mapped File

Hi, could someone explain to me what is a Memory Mapped File? Its uses? How could it be done in .NET?

thanks
0
jaxrpc
Asked:
jaxrpc
1 Solution
 
Bob LearnedCommented:
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
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now