MemoryMappedFile.OpenExisting 메서드

정의

시스템 메모리에서 명명된 기존의 메모리 매핑된 파일을 엽니다.

오버로드

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

메모리 매핑된 파일의 이름입니다.

반환

MemoryMappedFile

지정된 이름을 가진 메모리 매핑된 파일입니다.

특성

예외

mapName이(가) null인 경우

mapName이 빈 문자열인 경우

mapName에 지정된 파일이 없는 경우

예제

지속형 Memory-Mapped 파일 열기

다음 예제에서는 메서드 예제와 같이 CreateFromFile(String) 디스크의 파일에서 이미 생성된 메모리 ImgA 매핑된 파일을 엽니다.

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

메모리 매핑된 파일에 적용할 액세스 권한을 지정하는 열거형 값 중 하나입니다.

반환

MemoryMappedFile

지정된 특성을 가진 메모리 매핑된 파일입니다.

특성

예외

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

메모리 매핑된 파일에 적용할 액세스 권한을 지정하는 열거형 값 중 하나입니다.

inheritability
HandleInheritability

메모리 매핑된 파일의 핸들을 자식 프로세스가 상속할 수 있는지 여부를 지정하는 열거형 값 중 하나입니다. 기본값은 None입니다.

반환

MemoryMappedFile

지정된 특성을 가진 메모리 매핑된 파일입니다.

특성

예외

mapName이(가) null인 경우

mapName이 빈 문자열인 경우

desiredAccessRights가 유효한 MemoryMappedFileRights 열거형 값이 아닙니다.

또는 inheritability가 유효한 HandleInheritability 열거형 값이 아닙니다.

요청된 액세스는 메모리 매핑된 파일에 유효하지 않습니다.

mapName에 지정된 파일이 없는 경우

추가 정보

적용 대상