How to access Dictionary through shared memory mapped file?

Jul 17, 2012 at 7:05 PM

I need to create the memory mapped file in a Windows service and then access the populated memory via another .NET application (RIA services in this case).

The dictionary will be persisted long term on the file system. Is the file name used in creating the memory-mapped dictionary the means for sharing the dictionary contents across multiple .NET applications?

I have been looking at the code, but have not been able to figure out how to access the created object from another application other than the creating one.

Thanks, Warren

 

Jul 18, 2012 at 8:48 PM

After rereading another post, "What's missing for .NET4 is to use the mmf library which is built-in, instead of the current implementation.", what I asked about above may not be possible to do with the current product , but should be possible if the 4.0 upgrade is successful. Is that correct?

Thanks, Warren

Coordinator
Jul 19, 2012 at 7:39 PM

Hi,

The current version and the .NET4 version will be feature identical. It's a matter of switching out one library for another.

As for accessing the file from two applications I have not implemented this, but it should be trivial. If you use the .NET4 memory mapped API directly you should be able to do this as long as you use the same map name when accessing the mmf.

http://msdn.microsoft.com/en-us/library/dd989618.aspx

Thanks,
Mikael

Jul 19, 2012 at 10:11 PM
Wobba wrote:

If you use the .NET4 memory mapped API directly you should be able to do this as long as you use the same map name when accessing the mmf.

What I am confused about is that there are four generated files: FileName.hash, .key, .value, and .mmf. The MS memory mapped method as follows:

public static MemoryMappedFile CreateFromFile(
string path,
FileMode mode,
string mapName
)

requires a single file reference (e.g., MyFile.data). I did not see how that would map into the four files that are generated. Can you explain?

Thanks, Warren

Jul 20, 2012 at 5:13 AM
Edited Jul 20, 2012 at 12:36 PM

Mikael,

After thinking about what you said, I think the answer was staring me in the face... :-)   

In my case, mAdcOW.DataStructures.Dictionary<key, Value> MyDictionary is actually looking for FOUR memory mapped files to work. I was stuck in a ONE file mapping mentality and could not get passed it. In order to work with your data structure, all I should need to do is to map all four files and then it should just work. I'll give it a try tomorrow.

EDITED*****


After rethinking this again this morning, I do not think what I said above will work. I have no way of reassembling the four parts. I thought there might be a way of individually assigning the values to the instance in the different AppDomain, but I do not see a one-to-one mapping.

Were you saying that I only have to map the .mmf file? How do I gain access to the values? I am missing the mechanism for hooking the four parts into a form that the second dictionary instance in the separate AppDomain needs to operate properly. I guess I am still stuck.


Thanks again for the help. Warren

 

Coordinator
Jul 20, 2012 at 6:00 PM

Hi,

You are right that all files are needed. I will have to implement the mapping from multiple processes into the project. I was merely pointing to the docs to show how it can be done if you use mmf directly with your own code. Basically I would use the file name/path or a hash as the map name as it would be unique, and thus allow multiple processes to work on the same files.

Thanks,
Mikael