在我的Windows应用程序中,我想使用内存映射文件。网上有各种文章/博客,它们有足够的信息来创建内存映射文件。我正在创建2个内存映射文件,现在我想对这些文件执行一些操作,例如读取其内容,向其中添加一些内容,从中删除一些内容。所有这些可能会有更多的信息,但不幸的是我找不到任何东西。 下面是我用来编写内存映射文件的函数。读取,写入,追加,删除内存映射文件
// Stores the path to the selected folder in the memory mapped file
public void CreateMMFFile(string folderName, MemoryMappedFile mmf, string fileName)
{
// Lock
bool mutexCreated;
Mutex mutex = new Mutex(true, fileName, out mutexCreated);
try
{
using (MemoryMappedViewStream stream = mmf.CreateViewStream())
{
using (StreamWriter writer = new StreamWriter(stream, System.Text.Encoding.Unicode))
{
try
{
string[] files = System.IO.Directory.GetFiles(folderName, "*.*", System.IO.SearchOption.AllDirectories);
foreach (string str in files)
{
writer.WriteLine(str);
}
}
catch (Exception ex)
{
Debug.WriteLine("Unable to write string. " + ex);
}
finally
{
mutex.ReleaseMutex();
}
}
}
}
catch (Exception ex)
{
Debug.WriteLine("Unable to monitor memory file. " + ex);
}
}
如果有人可以帮助我,那将是非常感激。
[MSDN文档示例](http://msdn.microsoft.com/en-us/library/dd997372.aspx)的哪个部分是您特别有问题的理解? – 2012-03-01 05:59:54
我没有这样说过。下投票?原因?? – 2012-03-01 06:07:02
文档(特别是文档中的示例)包含从MMF读取和写入的例子,所以我很困惑;你在问什么? – 2012-03-01 06:08:49