Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memory Mapped Files .NET

I have a project and it needs to access a large amount of proprietary data in ASP.NET. This was done on the Linux/PHP by loading the data in shared memory. I was wondering if trying to use Memory Mapped Files would be the way to go, or if there is a better way with better .NET support. I was thinking of using the Data Cache but not sure of all the pitfalls of size of data being saved in the Cache.

like image 544
CSharpAtl Avatar asked Dec 10 '08 19:12

CSharpAtl


People also ask

What are the advantages of memory mapped files?

The principal benefits of memory-mapping are efficiency, faster file access, the ability to share memory between applications, and more efficient coding.

Are memory mapped files faster?

Accessing memory mapped files is faster than using direct read and write operations for two reasons. Firstly, a system call is orders of magnitude slower than a simple change to a program's local memory.

How big are memory mapped files?

Memory-mapped files cannot be larger than 2GB on 32-bit systems. When a memmap causes a file to be created or extended beyond its current size in the filesystem, the contents of the new part are unspecified.

What do you mean by mapping files into memory?

File mapping is the process of mapping the disk sectors of a file into the virtual memory space of a process. Once mapped, your app accesses the file as if it were entirely resident in memory.


2 Answers

I know this is a bit late, but the .NET 4.0 framework now supports memory-mapped files out of the box:

http://blogs.msdn.com/salvapatuel/archive/2009/06/08/working-with-memory-mapped-files-in-net-4.aspx

like image 63
Titian Cernicova-Dragomir Avatar answered Oct 06 '22 02:10

Titian Cernicova-Dragomir


If you are looking for a Memory Mapped library for C#, take a peek at Tomas Restrepo's filemap wrapper. It's licensed under the LGPL.

like image 23
Filip Frącz Avatar answered Oct 06 '22 04:10

Filip Frącz