MemoryMappedFile.OpenExisting メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
システム メモリ内の既存の名前付きメモリ マップト ファイルを開きます。
オーバーロード
| 名前 | 説明 |
|---|---|
| OpenExisting(String) |
システム メモリ内の指定した名前を持つ既存のメモリ マップト ファイルを開きます。 |
| OpenExisting(String, MemoryMappedFileRights) |
システム メモリ内の指定された名前とアクセス権を持つ既存のメモリ マップト ファイルを開きます。 |
| OpenExisting(String, MemoryMappedFileRights, HandleInheritability) |
指定した名前、アクセス権、およびシステム メモリ内の継承可能性を持つ、既存のメモリ マップト ファイルを開きます。 |
OpenExisting(String)
システム メモリ内の指定した名前を持つ既存のメモリ マップト ファイルを開きます。
public:
static System::IO::MemoryMappedFiles::MemoryMappedFile ^ OpenExisting(System::String ^ mapName);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.IO.MemoryMappedFiles.MemoryMappedFile OpenExisting(string mapName);
public static System.IO.MemoryMappedFiles.MemoryMappedFile OpenExisting(string mapName);
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member OpenExisting : string -> System.IO.MemoryMappedFiles.MemoryMappedFile
static member OpenExisting : string -> System.IO.MemoryMappedFiles.MemoryMappedFile
Public Shared Function OpenExisting (mapName As String) As MemoryMappedFile
パラメーター
- mapName
- String
メモリ マップト ファイルの名前。
返品
指定した名前を持つメモリ マップト ファイル。
- 属性
例外
mapName は nullです。
mapName は空の文字列です。
mapNameに指定されたファイルが存在しません。
例
永続化された Memory-Mapped ファイルを開く
次の例では、(ImgA メソッドの例に示すように) ディスク上のファイルから既に作成されている CreateFromFile(String) という名前のメモリ マップト ファイルを開きます。
using System;
using System.IO.MemoryMappedFiles;
using System.Runtime.InteropServices;
class Program
{
static void Main(string[] args)
{
// Assumes another process has created the memory-mapped file.
using (var mmf = MemoryMappedFile.OpenExisting("ImgA"))
{
using (var accessor = mmf.CreateViewAccessor(4000000, 2000000))
{
int colorSize = Marshal.SizeOf(typeof(MyColor));
MyColor color;
// Make changes to the view.
for (long i = 0; i < 1500000; i += colorSize)
{
accessor.Read(i, out color);
color.Brighten(20);
accessor.Write(i, ref color);
}
}
}
}
}
public struct MyColor
{
public short Red;
public short Green;
public short Blue;
public short Alpha;
// Make the view brigher.
public void Brighten(short value)
{
Red = (short)Math.Min(short.MaxValue, (int)Red + value);
Green = (short)Math.Min(short.MaxValue, (int)Green + value);
Blue = (short)Math.Min(short.MaxValue, (int)Blue + value);
Alpha = (short)Math.Min(short.MaxValue, (int)Alpha + value);
}
}
Imports System.IO.MemoryMappedFiles
Imports System.Runtime.InteropServices
Class Program
Public Shared Sub Main(ByVal args As String())
' Assumes another process has created the memory-mapped file.
Using mmf = MemoryMappedFile.OpenExisting("ImgA")
Using accessor = mmf.CreateViewAccessor(4000000, 2000000)
Dim colorSize As Integer = Marshal.SizeOf(GetType(MyColor))
Dim color As MyColor
' Make changes to the view.
Dim i As Long = 0
While i < 1500000
accessor.Read(i, color)
color.Brighten(30)
accessor.Write(i, color)
i += colorSize
End While
End Using
End Using
End Sub
End Class
Public Structure MyColor
Public Red As Short
Public Green As Short
Public Blue As Short
Public Alpha As Short
' Make the view brigher.
Public Sub Brighten(ByVal value As Short)
Red = CShort(Math.Min(Short.MaxValue, CInt(Red) + value))
Green = CShort(Math.Min(Short.MaxValue, CInt(Green) + value))
Blue = CShort(Math.Min(Short.MaxValue, CInt(Blue) + value))
Alpha = CShort(Math.Min(Short.MaxValue, CInt(Alpha) + value))
End Sub
End Structure
非永続化 Memory-Mapped ファイルを開く
次の例では、プロセス間通信に使用されるメモリ マップト ファイルを開きます。 このコード例は、 CreateNew(String, Int64) メソッドで提供されるより大きな例の一部です。
注釈
メモリ マップファイルは、永続化されたメモリ マップト ファイル (ディスク上のファイルに関連付けられている) または非永続化のいずれかです。
こちらもご覧ください
適用対象
OpenExisting(String, MemoryMappedFileRights)
システム メモリ内の指定された名前とアクセス権を持つ既存のメモリ マップト ファイルを開きます。
public:
static System::IO::MemoryMappedFiles::MemoryMappedFile ^ OpenExisting(System::String ^ mapName, System::IO::MemoryMappedFiles::MemoryMappedFileRights desiredAccessRights);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.IO.MemoryMappedFiles.MemoryMappedFile OpenExisting(string mapName, System.IO.MemoryMappedFiles.MemoryMappedFileRights desiredAccessRights);
public static System.IO.MemoryMappedFiles.MemoryMappedFile OpenExisting(string mapName, System.IO.MemoryMappedFiles.MemoryMappedFileRights desiredAccessRights);
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member OpenExisting : string * System.IO.MemoryMappedFiles.MemoryMappedFileRights -> System.IO.MemoryMappedFiles.MemoryMappedFile
static member OpenExisting : string * System.IO.MemoryMappedFiles.MemoryMappedFileRights -> System.IO.MemoryMappedFiles.MemoryMappedFile
Public Shared Function OpenExisting (mapName As String, desiredAccessRights As MemoryMappedFileRights) As MemoryMappedFile
パラメーター
- mapName
- String
開くメモリ マップト ファイルの名前。
- desiredAccessRights
- MemoryMappedFileRights
メモリ マップト ファイルに適用するアクセス権を指定する列挙値の 1 つ。
返品
指定した特性を持つメモリ マップト ファイル。
- 属性
例外
mapName は nullです。
mapName は空の文字列です。
desiredAccessRights が有効な MemoryMappedFileRights 列挙値ではありません。
mapNameに指定されたファイルが存在しません。
こちらもご覧ください
適用対象
OpenExisting(String, MemoryMappedFileRights, HandleInheritability)
指定した名前、アクセス権、およびシステム メモリ内の継承可能性を持つ、既存のメモリ マップト ファイルを開きます。
public:
static System::IO::MemoryMappedFiles::MemoryMappedFile ^ OpenExisting(System::String ^ mapName, System::IO::MemoryMappedFiles::MemoryMappedFileRights desiredAccessRights, System::IO::HandleInheritability inheritability);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.IO.MemoryMappedFiles.MemoryMappedFile OpenExisting(string mapName, System.IO.MemoryMappedFiles.MemoryMappedFileRights desiredAccessRights, System.IO.HandleInheritability inheritability);
public static System.IO.MemoryMappedFiles.MemoryMappedFile OpenExisting(string mapName, System.IO.MemoryMappedFiles.MemoryMappedFileRights desiredAccessRights, System.IO.HandleInheritability inheritability);
[System.Security.SecurityCritical]
public static System.IO.MemoryMappedFiles.MemoryMappedFile OpenExisting(string mapName, System.IO.MemoryMappedFiles.MemoryMappedFileRights desiredAccessRights, System.IO.HandleInheritability inheritability);
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member OpenExisting : string * System.IO.MemoryMappedFiles.MemoryMappedFileRights * System.IO.HandleInheritability -> System.IO.MemoryMappedFiles.MemoryMappedFile
static member OpenExisting : string * System.IO.MemoryMappedFiles.MemoryMappedFileRights * System.IO.HandleInheritability -> System.IO.MemoryMappedFiles.MemoryMappedFile
[<System.Security.SecurityCritical>]
static member OpenExisting : string * System.IO.MemoryMappedFiles.MemoryMappedFileRights * System.IO.HandleInheritability -> System.IO.MemoryMappedFiles.MemoryMappedFile
Public Shared Function OpenExisting (mapName As String, desiredAccessRights As MemoryMappedFileRights, inheritability As HandleInheritability) As MemoryMappedFile
パラメーター
- mapName
- String
開くメモリ マップト ファイルの名前。
- desiredAccessRights
- MemoryMappedFileRights
メモリ マップト ファイルに適用するアクセス権を指定する列挙値の 1 つ。
- inheritability
- HandleInheritability
メモリ マップト ファイルのハンドルを子プロセスで継承できるかどうかを指定する列挙値の 1 つ。 既定値は None です。
返品
指定した特性を持つメモリ マップト ファイル。
- 属性
例外
mapName は nullです。
mapName は空の文字列です。
desiredAccessRights が有効な MemoryMappedFileRights 列挙値ではありません。
-又は-
inheritability が有効な HandleInheritability 列挙値ではありません。
要求されたアクセスは、メモリ マップト ファイルに対して無効です。
mapNameに指定されたファイルが存在しません。