Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

MemoryMappedFile::CreateFromFile Method (FileStream^, String^, Int64, MemoryMappedFileAccess, HandleInheritability, Boolean)

.NET Framework (current version)
 

Creates a memory-mapped file from an existing file with the specified access mode, name, inheritability, and capacity.

Namespace:   System.IO.MemoryMappedFiles
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

mapName is null or an empty string.

-or-

capacity and the length of the file are zero.

-or-

access is set to Write or Write enumeration value, which is not allowed.

-or-

access is set to Read and capacity is larger than the length of filestream.

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.

.NET Framework
Available since 4.6
Return to top
Show:
© 2017 Microsoft