While translating a Java project to C#, i got stuck with the following piece:
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).
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.
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.