简体   繁体   English

C#等效于Java内存映射方法

[英]C# equivalent of Java Memory mapping methods

While translating a Java project to C#, i got stuck with the following piece: 在将Java项目转换为C#时,我陷入了以下困境:

RandomAccessFile raf = new RandomAccessFile(fileName, "r");
FileChannel channel = raf.getChannel();
MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, length);

I'm not familiar with the memory mapping conception, I found a MemoryMappedFile class in C#, but don't know how to use it properly like in the Java code above (the MappedByteBuffer is used to obtain a large binary file, about 600-700MB). 我不熟悉内存映射的概念,我在C#中找到了MemoryMappedFile类,但不知道如何像上面的Java代码中那样正确使用它( MappedByteBuffer用于获取大的二进制文件,大约600- 700MB)。

Can anyone tell me how to translate the piece above properly? 谁能告诉我如何正确翻译以上内容?

MemoryMappedFile mmf = MemoryMappedFile.CreateFromFile(fileName, FileMode.Read);
using (MemoryMappedViewStream vs = mmf.CreateViewStream()) {
    // perform stream operations
}

A MemoryMappedViewStream is a thin veneer onto the memory. MemoryMappedViewStream是内存上的薄薄单板。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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