MemoryMappedFile.OpenExisting 메서드

정의

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

오버로드

Name Description
OpenExisting(String)

시스템 메모리에 지정된 이름을 포함하는 기존 메모리 매핑 파일을 엽니다.

OpenExisting(String, MemoryMappedFileRights)

시스템 메모리에서 지정된 이름 및 액세스 권한이 있는 기존 메모리 매핑 파일을 엽니다.

OpenExisting(String, MemoryMappedFileRights, HandleInheritability)

시스템 메모리에서 지정된 이름, 액세스 권한 및 상속 가능성이 있는 기존 메모리 매핑 파일을 엽니다.

OpenExisting(String)

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

시스템 메모리에 지정된 이름을 포함하는 기존 메모리 매핑 파일을 엽니다.

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

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

반품

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

특성

예외

mapNamenull입니다.

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)

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

시스템 메모리에서 지정된 이름 및 액세스 권한이 있는 기존 메모리 매핑 파일을 엽니다.

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

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

반품

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

특성

예외

mapNamenull입니다.

mapName 은 빈 문자열입니다.

desiredAccessRights 가 유효한 MemoryMappedFileRights 열거형 값이 아닌 경우

지정된 mapName 파일이 없습니다.

추가 정보

적용 대상

OpenExisting(String, MemoryMappedFileRights, HandleInheritability)

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

시스템 메모리에서 지정된 이름, 액세스 권한 및 상속 가능성이 있는 기존 메모리 매핑 파일을 엽니다.

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입니다.

반품

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

특성

예외

mapNamenull입니다.

mapName 은 빈 문자열입니다.

desiredAccessRights 가 유효한 MemoryMappedFileRights 열거형 값이 아닌 경우

-또는-

inheritability 가 유효한 HandleInheritability 열거형 값이 아닌 경우

메모리 매핑된 파일에 대해 요청된 액세스가 잘못되었습니다.

지정된 mapName 파일이 없습니다.

추가 정보

적용 대상