MemoryMappedFile::CreateFromFile Method (FileStream^, String^, Int64, MemoryMappedFileAccess, HandleInheritability, Boolean)
Creates a memory-mapped file from an existing file with the specified access mode, name, inheritability, and capacity.
Assembly: System.Core (in System.Core.dll)
public: static MemoryMappedFile^ CreateFromFile( FileStream^ fileStream, String^ mapName, long long capacity, MemoryMappedFileAccess access, HandleInheritability inheritability, bool leaveOpen )
Parameters
- fileStream
-
Type:
System.IO::FileStream^
The file stream of the existing file.
- mapName
-
Type:
System::String^
A name to assign to the memory-mapped file.
- capacity
-
Type:
System::Int64
The maximum size, in bytes, to allocate to the memory-mapped file. Specify 0 to set the capacity to the size of filestream.
- access
-
Type:
System.IO.MemoryMappedFiles::MemoryMappedFileAccess
One of the enumeration values that specifies the type of access allowed to the memory-mapped file.
This parameter can’t be set to Write.
- inheritability
-
Type:
System.IO::HandleInheritability
One of the enumeration values that specifies whether a handle to the memory-mapped file can be inherited by a child process. The default is None.
- leaveOpen
-
Type:
System::Boolean
A value that indicates whether to close the source file stream when the MemoryMappedFile is disposed.
Return Value
Type: System.IO.MemoryMappedFiles::MemoryMappedFile^A memory-mapped file that has the specified characteristics.
| Exception | Condition |
|---|---|
| ArgumentException | |
| ArgumentNullException | fileStream is null. |
| ArgumentOutOfRangeException | capacity is less than zero. -or- capacity is less than the file size. -or- access is not a valid MemoryMappedFileAccess enumeration value. -or- inheritability is not a valid HandleInheritability enumeration value. |
Available since 4.6