2

Does anyone know an Open Source implementation in C# using Shared Memory pre. .NET 4.0 (where we don't have the Memory Mapped file implementations.

Preferably using id indexes.

3
  • what do you think by "id indexes"? Commented Apr 1, 2011 at 17:39
  • Guess "same memory address/id points to same memory location". Commented Apr 1, 2011 at 17:41
  • well most i have found is based in "string names" for objects, and that just seems like an inefficient mapping, and I am using int's currently for a disk based cache. Commented Apr 1, 2011 at 18:41

3 Answers 3

2
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr CreateFileMapping(
    IntPtr hFile,
    IntPtr lpFileMappingAttributes,
    FileMapProtection flProtect,
    uint dwMaximumSizeHigh,
    uint dwMaximumSizeLow,
    [MarshalAs(UnmanagedType.LPTStr)] string lpName);

See here for more information

http://www.pinvoke.net/default.aspx/kernel32.createfilemapping

and

http://msdn.microsoft.com/en-us/library/aa366551(v=vs.85).aspx

The C# Cookbook contains an implementation of SharedMemoryManager that you can view here: http://csharp.codefetch.com/example/p1/MutexFun/SharedMemoryManager.cs

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, i have quite a few resources on how to implement it my self... but that takes time and I need it for a larger project so I would like to jump the hoop if I could. But Cheers Anyways :)
2

Enterprise Library has a Caching Application Block. See here: Microsoft Enterprise Library 5.0 – April 2010 for the latest version (.NET 3.5 and .NET 4). Older versions also have this caching application block if you have lower requirements.

2 Comments

I know of the Caching block in ETLIB, but don't know to much about it's details... Just a Quick question if you care to awnser, will it be able to share cache between app domains and processes (on same computer) which is not DB or File based? (AKA Shared Memory Backing Store)... Im running out for drinks now so don't quite have the time to look into it now, but will if I have to... But cheers for reminding me that it existed.
@Jens - I think you can do this yes, and the cache can be, I quote "in-memory, or disk-based using files or a database" (from here: msdn.microsoft.com/en-us/library/ee658105.aspx), plus it can be extended as well.
1

You have couple of choices.

I would choose memory mapped files as you will get much better performances. Everything depends on what you are trying to achieve. Take a look at .NET Framework 4.0. implementation of System.IO.MemoryMappedFile.

1 Comment

I Have looked at that, and well... Memory mapped files was the idea if I had to do the implementation my self... was hoping to get around that... The 4.0 implementation seemed a bit more that what I needed in reality... so "reimplementing it in it's whole" in .NET 3.5 is not needed... but will look at your links tomorrow, i think I have already been by some of them... as I wrote to another... I was really hoping to make a shortcut >.<.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.