Edit

Share via


MemoryMappedFile.CreateOrOpen Method

Definition

Creates or opens a memory-mapped file in system memory.

Overloads

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

Creates or opens a memory-mapped file that has the specified name, capacity, access type, memory allocation, security permissions, and inheritability 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.

CreateOrOpen(String, Int64)

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

CreateOrOpen(String, Int64, MemoryMappedFileAccess)

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

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

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

public:
 static System::IO::MemoryMappedFiles::MemoryMappedFile ^ CreateOrOpen(System::String ^ mapName, long capacity, System::IO::MemoryMappedFiles::MemoryMappedFileAccess access, System::IO::MemoryMappedFiles::MemoryMappedFileOptions options, System::IO::MemoryMappedFiles::MemoryMappedFileSecurity ^ memoryMappedFileSecurity, System::IO::HandleInheritability inheritability);
[System.Security.SecurityCritical]
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);
[<System.Security.SecurityCritical>]
static member CreateOrOpen : string * int64 * System.IO.MemoryMappedFiles.MemoryMappedFileAccess * System.IO.MemoryMappedFiles.MemoryMappedFileOptions * System.IO.MemoryMappedFiles.MemoryMappedFileSecurity * System.IO.HandleInheritability -> System.IO.MemoryMappedFiles.MemoryMappedFile
Public Shared Function CreateOrOpen (mapName As String, capacity As Long, access As MemoryMappedFileAccess, options As MemoryMappedFileOptions, memoryMappedFileSecurity As MemoryMappedFileSecurity, inheritability As HandleInheritability) As MemoryMappedFile

Parameters

mapName
String

The name of 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.

Attributes

Exceptions

mapName is null.

mapName is an empty string.

-or-

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

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.

See also

Applies to

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

Source:
MemoryMappedFile.cs
Source:
MemoryMappedFile.cs
Source:
MemoryMappedFile.cs

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(System::String ^ mapName, long capacity, System::IO::MemoryMappedFiles::MemoryMappedFileAccess access, System::IO::MemoryMappedFiles::MemoryMappedFileOptions options, System::IO::HandleInheritability inheritability);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
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);
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);
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member CreateOrOpen : string * int64 * System.IO.MemoryMappedFiles.MemoryMappedFileAccess * System.IO.MemoryMappedFiles.MemoryMappedFileOptions * System.IO.HandleInheritability -> System.IO.MemoryMappedFiles.MemoryMappedFile
static member CreateOrOpen : string * int64 * System.IO.MemoryMappedFiles.MemoryMappedFileAccess * System.IO.MemoryMappedFiles.MemoryMappedFileOptions * System.IO.HandleInheritability -> System.IO.MemoryMappedFiles.MemoryMappedFile
Public Shared Function CreateOrOpen (mapName As String, capacity As Long, access As MemoryMappedFileAccess, options As MemoryMappedFileOptions, inheritability As HandleInheritability) As MemoryMappedFile

Parameters

mapName
String

The name of 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.

Attributes

Exceptions

mapName is null.

mapName is an empty string.

-or-

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

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.

Applies to

CreateOrOpen(String, Int64)

Source:
MemoryMappedFile.cs
Source:
MemoryMappedFile.cs
Source:
MemoryMappedFile.cs

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

public:
 static System::IO::MemoryMappedFiles::MemoryMappedFile ^ CreateOrOpen(System::String ^ mapName, long capacity);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateOrOpen (string mapName, long capacity);
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateOrOpen (string mapName, long capacity);
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member CreateOrOpen : string * int64 -> System.IO.MemoryMappedFiles.MemoryMappedFile
static member CreateOrOpen : string * int64 -> System.IO.MemoryMappedFiles.MemoryMappedFile
Public Shared Function CreateOrOpen (mapName As String, capacity As Long) As MemoryMappedFile

Parameters

mapName
String

The name of 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.

Attributes

Exceptions

mapName is an empty string.

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.

See also

Applies to

CreateOrOpen(String, Int64, MemoryMappedFileAccess)

Source:
MemoryMappedFile.cs
Source:
MemoryMappedFile.cs
Source:
MemoryMappedFile.cs

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

public:
 static System::IO::MemoryMappedFiles::MemoryMappedFile ^ CreateOrOpen(System::String ^ mapName, long capacity, System::IO::MemoryMappedFiles::MemoryMappedFileAccess access);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateOrOpen (string mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access);
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateOrOpen (string mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access);
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member CreateOrOpen : string * int64 * System.IO.MemoryMappedFiles.MemoryMappedFileAccess -> System.IO.MemoryMappedFiles.MemoryMappedFile
static member CreateOrOpen : string * int64 * System.IO.MemoryMappedFiles.MemoryMappedFileAccess -> System.IO.MemoryMappedFiles.MemoryMappedFile
Public Shared Function CreateOrOpen (mapName As String, capacity As Long, access As MemoryMappedFileAccess) As MemoryMappedFile

Parameters

mapName
String

The name of 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.

Attributes

Exceptions

mapName is null.

mapName is an empty string.

-or-

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

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.

See also

Applies to