开发者

C# Shared Memory Cache

D开发者_C百科oes 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.


[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


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.


You have couple of choices.

  • Memory mapped files - Working with memory mapped files in .NET 4
  • IPC or RPC - Take a look at this examples
  • DCOM - Distributed Component Object Model
  • Native DLL - How do I share data in my DLL with an application or with other DLLs?
  • Your own data sharing/caching windows service based on TCP/IP (Socket server) - WCF

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜