MemoryMappedFile.CreateOrOpen Method

Definition

Overloads

CreateOrOpen(String, Int64, MemoryMappedFileAccess, MemoryMappedFileOptions, HandleInheritability)

Creates a new empty memory mapped file or opens an existing memory mapped file if one exists with the same name. If opening an existing file, the capacity, options, and memory arguments will be ignored.

CreateOrOpen(String, Int64, MemoryMappedFileAccess, MemoryMappedFileOptions, MemoryMappedFileSecurity, HandleInheritability)

Creates or opens a memory-mapped file that has the specified capacity, access type, memory allocation, security permissions, and inheritability in system memory.

CreateOrOpen(String, Int64)

Creates or opens a memory-mapped file that has the specified capacity in system memory.

CreateOrOpen(String, Int64, MemoryMappedFileAccess)

Creates or opens a memory-mapped file that has the specified capacity and access type in system memory.

CreateOrOpen(String, Int64, MemoryMappedFileAccess, MemoryMappedFileOptions, HandleInheritability)

Creates a new empty memory mapped file or opens an existing memory mapped file if one exists with the same name. If opening an existing file, the capacity, options, and memory arguments will be ignored.

public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateOrOpen (string mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access, System.IO.MemoryMappedFiles.MemoryMappedFileOptions options, System.IO.HandleInheritability inheritability);
Parameters
mapName
String

A name to assign to the memory-mapped file.

capacity
Int64

The maximum size, in bytes, to allocate to the memory-mapped file.

access
MemoryMappedFileAccess

One of the enumeration values that specifies the type of access allowed to the memory-mapped file. The default is ReadWrite.

options
MemoryMappedFileOptions

A bitwise combination of values that indicate the memory allocation options to apply to the file.

inheritability
HandleInheritability

A value that specifies whether a handle to the memory-mapped file can be inherited by a child process. The default is None.

Returns

A memory-mapped file that has the specified characteristics.

Exceptions

mapName is an empty string.

-or-

access is set to write-only with the Write enumeration value.

mapName is null.

capacity is greater than the size of the logical address space.

-or-

capacity is less than or equal to zero.

-or-

access is not a valid MemoryMappedFileAccess enumeration value.

-or-

inheritability is not a valid HandleInheritability enumeration value.

The operating system denied the specified access to the file; for example, access is set to Write or ReadWrite, but the file or directory is read-only.

CreateOrOpen(String, Int64, MemoryMappedFileAccess, MemoryMappedFileOptions, MemoryMappedFileSecurity, HandleInheritability)

Creates or opens a memory-mapped file that has the specified capacity, access type, memory allocation, security permissions, and inheritability in system memory.

public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateOrOpen (string mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access, System.IO.MemoryMappedFiles.MemoryMappedFileOptions options, System.IO.MemoryMappedFiles.MemoryMappedFileSecurity memoryMappedFileSecurity, System.IO.HandleInheritability inheritability);
Parameters
mapName
String

A name to assign to the memory-mapped file.

capacity
Int64

The maximum size, in bytes, to allocate to the memory-mapped file.

access
MemoryMappedFileAccess

One of the enumeration values that specifies the type of access allowed to the memory-mapped file. The default is ReadWrite.

options
MemoryMappedFileOptions

A bitwise combination of enumeration values that specifies memory allocation options for the memory-mapped file.

memoryMappedFileSecurity
MemoryMappedFileSecurity

The permissions that can be granted for file access and operations on memory-mapped files.

This parameter can be null.

inheritability
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.

Returns

A memory-mapped file that has the specified characteristics.

Exceptions

mapName is an empty string.

-or-

access is set to write-only with the Write enumeration value.

mapName is null.

capacity is greater than the size of the logical address space.

-or-

capacity is less than or equal to zero.

-or-

access is not a valid MemoryMappedFileAccess enumeration value.

-or-

inheritability is not a valid HandleInheritability enumeration value.

The operating system denied the specified access to the file; for example, access is set to Write or ReadWrite, but the file or directory is read-only.

Remarks

Use this method to create or open a memory-mapped file that is not persisted (that is, not associated with a file on disk), which you can use to share data between processes.

CreateOrOpen(String, Int64)

Creates or opens a memory-mapped file that has the specified capacity in system memory.

public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateOrOpen (string mapName, long capacity);
Parameters
mapName
String

A name to assign to the memory-mapped file.

capacity
Int64

The maximum size, in bytes, to allocate to the memory-mapped file.

Returns

A memory-mapped file that has the specified name and size.

Exceptions

mapName is an empty string.

mapName is null.

capacity is greater than the size of the logical address space.

-or-

capacity is less than or equal to zero.

Remarks

Use this method to create or open a memory-mapped file that is not persisted (that is, not associated with a file on disk), which you can use to share data between processes.

CreateOrOpen(String, Int64, MemoryMappedFileAccess)

Creates or opens a memory-mapped file that has the specified capacity and access type in system memory.

public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateOrOpen (string mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access);
Parameters
mapName
String

A name to assign to the memory-mapped file.

capacity
Int64

The maximum size, in bytes, to allocate to the memory-mapped file.

access
MemoryMappedFileAccess

One of the enumeration values that specifies the type of access allowed to the memory-mapped file. The default is ReadWrite.

Returns

A memory-mapped file that has the specified characteristics.

Exceptions

mapName is an empty string.

-or-

access is set to write-only with the Write enumeration value.

mapName is null.

capacity is greater than the size of the logical address space.

-or-

capacity is less than or equal to zero.

-or-

access is not a valid MemoryMappedFileAccess enumeration value.

The operating system denied the specified access to the file; for example, access is set to Write or ReadWrite, but the file or directory is read-only.

Remarks

Use this method to create or open a memory-mapped file that is not persisted (that is, not associated with a file on disk), which you can use to share data between processes.