简体   繁体   中英

Can I create a virtual disk in memory programatically?

For performance purposes I want to write to memory, where an external application can read. I can't link both applications together, so I think the only way is by writing a file. But writing it to a physical disk isn't fast enough. I want to mount a virtual partition so any application can access it. How to do it?

You don't need to go as far as creating a virtual disk to share memory between processes on Windows - you can create a shared memory block, and multiple processes can then access that memory.

See this MSDN article: Creating Named Shared Memory

您可以使用命名管道在应用程序之间传输数据。

I have seen some commersial avaliable ramdisk implementation for .net but I cant seem to find it right now.

Another option might be: C# accessing memory map file

I wish you can use .NET 4.0 :)

.NET 4.0 introduces memory mapped file.

Gunnar Peipman blogged nicely in the following link: .Net Framework 4.0: Using memory mapped files

In his blog, " Memory mapped files are useful when you need to do in-memory data manipulation and your data structures are large. For large in-memory data the performance of memory mapped file is the best. It is much faster than MemoryStream. And like files on hard disc, memory mapped files can be shared between different programs ."

His blog also contains the sample code as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM