/// <summary> /// Creates a FileMappingViewAccessor that maps to a view of the memory-mapped file, /// and that has the specified offset and size. /// </summary> /// <param name="offset">The byte at which to start the view.</param> /// <param name="size">The size of the view. Specify 0 (zero) to create a view that /// starts at offset and ends approximately at the end of the memory-mapped file. /// </param> /// <returns>A randomly accessible block of memory.</returns> public FileMappingViewAccessor CreateViewAccessor(long offset, long size) { long lengthFromOffsetToTheEnd = (size == 0) ? this.fileSize - offset : size; SafeFileMappingViewHandle handle = new SafeFileMappingViewHandle(Win32.MapViewOfFile( this.FileMappingHandle, Win32.FILE_MAP_WRITE, unchecked ((UInt32)(offset >> 32)), unchecked ((UInt32)(offset & 0xFFFFFFFF)), unchecked ((IntPtr)size) ), (ulong)lengthFromOffsetToTheEnd); if (handle.IsInvalid) { throw new Exception("Could not create a view of memory-mapped file."); } return(new FileMappingViewAccessor(handle, offset, lengthFromOffsetToTheEnd)); // throws // ArgumentOutOfRangeException // UnauthorizedAccessException // IOException }
internal FileMappingViewAccessor(SafeFileMappingViewHandle handle, long offset, long capacity) { Debug.Assert(handle != null); Debug.Assert(!handle.IsInvalid, "handle is invalid"); FileMappingViewHandle = handle; PointerOffset = offset; Capacity = capacity; }
/// <summary> /// Creates a stream that maps to a view of the memory-mapped file, /// and that has the specified offset and size. /// </summary> /// <param name="offset">The byte at which to start the view.</param> /// <param name="size">The size of the view. Specify 0 (zero) to create a view that /// starts at offset and ends approximately at the end of the memory-mapped file.</param> /// <returns>A stream of memory that has the specified offset and size.</returns> public FileMappingViewStream CreateViewStream(long offset, long size) { long lengthFromOffsetToTheEnd = (size == 0) ? this.fileSize - offset : size; // TODO: implement SafeFileMappingViewHandle handle = new SafeFileMappingViewHandle(IntPtr.Zero, (ulong)lengthFromOffsetToTheEnd); // = return(new FileMappingViewStream(handle, offset, lengthFromOffsetToTheEnd)); }
internal FileMappingViewStream(SafeFileMappingViewHandle handle, long offset, long capacity) { }