How can I quickly read bytes from a memory mapped file in .NET?

后端 未结 4 1445
日久生厌
日久生厌 2020-12-13 20:01

In some situations the MemoryMappedViewAccessor class just doesn\'t cut it for reading bytes efficiently; the best we get is the generic ReadArray

4条回答
  •  天涯浪人
    2020-12-13 20:33

    See this bug report: No way to determine internal offset used by MemoryMappedViewAccessor - Makes SafeMemoryMappedViewHandle property unusable.

    From the report:

    MemoryMappedViewAccessor has a SafeMemoryMappedViewHandle property, which returns the ViewHandle being used internally by the MemoryMappedView, but does not have any property to return the offset being used by the MemoryMappedView.

    As the MemoryMappedView is page aligning the offset requested in MemoryMappedFile.CreateViewAccessor(offset,size) it is impossible to use the SafeMemoryMappedViewHandle for anything useful without knowing the offset.

    Note that what we actually want to do is use the AcquirePointer(ref byte* pointer) method to allow some fast pointer based (possibly unmanaged) code to run. We're OK with the pointer being page aligned, but it must be possible to find out what the offset from the originally requested address is.

提交回复
热议问题