public static MemoryMappedFile CreateFromFile(string path, FileMode mode, string mapName, long capacity, MemoryMappedFileAccess access) { if (path == null) { throw new ArgumentNullException("path"); } if (path.Length == 0) { throw new ArgumentException("path"); } if (mapName != null && mapName.Length == 0) { throw new ArgumentException("mapName"); } if (mode == FileMode.Append) { throw new ArgumentException("mode"); } if (capacity < 0) { throw new ArgumentOutOfRangeException("capacity"); } IntPtr handle = MemoryMapImpl.OpenFile(path, mode, mapName, out capacity, access, MemoryMappedFileOptions.None); return(new MemoryMappedFile() { handle = handle, // fileAccess = access, // name = mapName, // fileCapacity = capacity }); }
public static MemoryMappedFile CreateFromFile(FileStream fileStream, string mapName, long capacity, MemoryMappedFileAccess access, MemoryMappedFileSecurity memoryMappedFileSecurity, HandleInheritability inheritability, bool leaveOpen) #endif { if (fileStream == null) { throw new ArgumentNullException("fileStream"); } if (mapName != null && mapName.Length == 0) { throw new ArgumentException("mapName"); } if ((capacity == 0 && fileStream.Length == 0) || (capacity > fileStream.Length)) { throw new ArgumentException("capacity"); } MemoryMapImpl.ConfigureFD(fileStream.Handle, inheritability); return(new MemoryMappedFile() { stream = fileStream, fileAccess = access, name = mapName, fileCapacity = capacity, keepOpen = leaveOpen }); }
unsafe void CreateStream(IntPtr handle, long offset, long size, MemoryMappedFileAccess access) { IntPtr base_address; MemoryMapImpl.Map(handle, offset, ref size, access, out mmap_handle, out base_address); FileAccess faccess; switch (access) { case MemoryMappedFileAccess.ReadWrite: faccess = FileAccess.ReadWrite; break; case MemoryMappedFileAccess.Read: faccess = FileAccess.Read; break; case MemoryMappedFileAccess.Write: faccess = FileAccess.Write; break; default: throw new NotImplementedException("access mode " + access + " not supported."); } Initialize((byte *)base_address, size, size, faccess); }
unsafe void CreateStream(int fd, long offset, long size, MemoryMappedFileAccess access) { int offset_diff; mmap_size = (ulong)size; MemoryMapImpl.Map(fd, offset, ref size, access, out mmap_addr, out offset_diff); FileAccess faccess; switch (access) { case MemoryMappedFileAccess.ReadWrite: faccess = FileAccess.ReadWrite; break; case MemoryMappedFileAccess.Read: faccess = FileAccess.Read; break; case MemoryMappedFileAccess.Write: faccess = FileAccess.Write; break; default: throw new NotImplementedException("access mode " + access + " not supported."); } Initialize((byte *)mmap_addr + offset_diff, size, size, faccess); }
public static MemoryMappedFile CreateFromFile(FileStream fileStream, string mapName, long capacity, MemoryMappedFileAccess access, MemoryMappedFileSecurity memoryMappedFileSecurity, HandleInheritability inheritability, bool leaveOpen) { if (fileStream == null) { throw new ArgumentNullException("fileStream"); } if (mapName != null && mapName.Length == 0) { throw new ArgumentException("mapName"); } if ((!MonoUtil.IsUnix && capacity == 0 && fileStream.Length == 0) || (capacity > fileStream.Length)) { throw new ArgumentException("capacity"); } IntPtr handle = MemoryMapImpl.OpenHandle(fileStream.SafeFileHandle.DangerousGetHandle(), mapName, out capacity, access, MemoryMappedFileOptions.None); MemoryMapImpl.ConfigureHandleInheritability(handle, inheritability); return(new MemoryMappedFile() { handle = handle, // fileAccess = access, // name = mapName, // fileCapacity = capacity, stream = fileStream, keepOpen = leaveOpen }); }
public static MemoryMappedFile CreateFromFile(string path, FileMode mode) { long capacity = 0; if (path == null) { throw new ArgumentNullException("path"); } if (path.Length == 0) { throw new ArgumentException("path"); } if (mode == FileMode.Append) { throw new ArgumentException("mode"); } IntPtr handle = MemoryMapImpl.OpenFile(path, mode, null, out capacity, MemoryMappedFileAccess.ReadWrite, MemoryMappedFileOptions.None); return(new MemoryMappedFile() { handle = handle, // fileAccess = MemoryMappedFileAccess.ReadWrite, // fileCapacity = capacity }); }
public static MemoryMappedFile CreateFromFile(string path, FileMode mode, string mapName, long capacity, MemoryMappedFileAccess access) { if (path == null) { throw new ArgumentNullException("path"); } if (path.Length == 0) { throw new ArgumentException("path"); } if (mapName != null && mapName.Length == 0) { throw new ArgumentException("mapName"); } if (mode == FileMode.Append) { throw new ArgumentException("mode"); } int fd = MemoryMapImpl.Open(path, mode, capacity, access); return(new MemoryMappedFile() { unix_fd = fd, fileAccess = access, name = mapName, fileCapacity = capacity }); }
unsafe void Create(long offset, long size, MemoryMappedFileAccess access) { int offset_diff; MemoryMapImpl.Map(file_handle, offset, ref size, access, out mmap_addr, out offset_diff); handle = new SafeMemoryMappedViewHandle((IntPtr)((long)mmap_addr + offset_diff), size); Initialize(handle, 0, size, ToFileAccess(access)); }
unsafe void Create(IntPtr handle, long offset, long size, MemoryMappedFileAccess access) { IntPtr base_address; MemoryMapImpl.Map(handle, offset, ref size, access, out mmap_handle, out base_address); safe_handle = new SafeMemoryMappedViewHandle(mmap_handle, base_address, size); Initialize(safe_handle, 0, size, ToFileAccess(access)); }
protected override void Dispose(bool disposing) { base.Dispose(disposing); lock (monitor) { if (mmap_handle != (IntPtr)(-1)) { MemoryMapImpl.Unmap(mmap_handle); mmap_handle = (IntPtr)(-1); } } }
internal unsafe static MemoryMappedView Create(IntPtr handle, long offset, long size, MemoryMappedFileAccess access) { IntPtr base_address; IntPtr mmap_handle; MemoryMapImpl.Map(handle, offset, ref size, access, out mmap_handle, out base_address); var safe_handle = new SafeMemoryMappedViewHandle(mmap_handle, base_address, size); // MemoryMapImpl.Map returns a base_address to the offset so MemoryMappedView is initiated // no offset. return(new MemoryMappedView(safe_handle, 0, size, access)); }
protected virtual void Dispose(bool disposing) { if (disposing) { if (stream != null) { if (keepOpen == false) { stream.Close(); } stream = null; } if (handle != IntPtr.Zero) { MemoryMapImpl.CloseMapping(handle); handle = IntPtr.Zero; } } }
protected virtual void Dispose(bool disposing) { if (disposing) { if (stream != null) { if (keepOpen == false) { stream.Close(); } unix_fd = -1; stream = null; } if (unix_fd != -1) { MemoryMapImpl.CloseFD(unix_fd); unix_fd = -1; } } }
static MemoryMappedFile CoreShmCreate(string mapName, long capacity, MemoryMappedFileAccess access, MemoryMappedFileOptions options, MemoryMappedFileSecurity memoryMappedFileSecurity, HandleInheritability inheritability, FileMode mode) { if (mapName != null && mapName.Length == 0) { throw new ArgumentException("mapName"); } if (capacity < 0) { throw new ArgumentOutOfRangeException("capacity"); } IntPtr handle = MemoryMapImpl.OpenFile(null, mode, mapName, out capacity, access, options); return(new MemoryMappedFile() { handle = handle, // fileAccess = access, // name = mapName, // fileCapacity = capacity }); }
public override void Flush() { MemoryMapImpl.Flush(mmap_handle); }
public void Flush() { MemoryMapImpl.Flush(file_handle); }
public override void Flush() { MemoryMapImpl.Flush(fd); }
public void Flush() { MemoryMapImpl.Flush(mmap_handle); }
public void Flush(IntPtr capacity) { MemoryMapImpl.Flush(m_viewHandle.DangerousGetHandle()); }