/// <summary> /// Build a FileMap object given a FileStream. /// </summary> /// <param name="f">File to be mapped. The stream can be closed because the handle /// is duplicated by the constructor. The file is released only when *both* handles /// are closed.</param> public FileMap(FileStream f) { unsafe { handle = Win32Mapping.CreateFileMapping(f.SafeFileHandle.DangerousGetHandle(), (void *)0, FileProtection.PAGE_READONLY, 0, 0, null); } }
/// <summary> /// Builds a mapped view of a mapped file. /// </summary> /// <param name="m">File mapping to use</param> /// <param name="off">Offset to be mapped</param> /// <param name="sz">Size of the view</param> public MapView(FileMap m, long off, int sz) { long basep = off & Win32Mapping.MaskOffset; int gap = (int)(off & Win32Mapping.MaskBase); unsafe { addr = (byte *)Win32Mapping.MapViewOfFile(m.Handle, FileMapAccess.FILE_MAP_READ, (int)(basep >> 32), (int)(basep & 0xFFFFFFFFL), sz); pb = addr + gap; size = sz; } }
/// <summary> /// Release the file mapping. /// </summary> private void Release() { Win32Mapping.CloseHandle(handle); }
/// <summary> /// Release the mapping /// </summary> private void Release() { unsafe { Win32Mapping.UnmapViewOfFile((void *)addr); } }