MemoryMappedFile 클래스

정의

메모리 매핑된 파일을 나타냅니다.

public ref class MemoryMappedFile : IDisposable
public class MemoryMappedFile : IDisposable
type MemoryMappedFile = class
    interface IDisposable
Public Class MemoryMappedFile
Implements IDisposable
상속
MemoryMappedFile
구현

예제

다음 예제에서는 매우 큰 파일의 일부에 대한 메모리 매핑된 보기를 만들고 보기의 일부를 조작합니다.

using System;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Runtime.InteropServices;

class Program
{
    static void Main(string[] args)
    {
        long offset = 0x10000000; // 256 megabytes
        long length = 0x20000000; // 512 megabytes

        // Create the memory-mapped file.
        using (var mmf = MemoryMappedFile.CreateFromFile(@"c:\ExtremelyLargeImage.data", FileMode.Open,"ImgA"))
        {
            // Create a random access view, from the 256th megabyte (the offset)
            // to the 768th megabyte (the offset plus length).
            using (var accessor = mmf.CreateViewAccessor(offset, length))
            {
                int colorSize = Marshal.SizeOf(typeof(MyColor));
                MyColor color;

                // Make changes to the view.
                for (long i = 0; i < length; i += colorSize)
                {
                    accessor.Read(i, out color);
                    color.Brighten(10);
                    accessor.Write(i, ref color);
                }
            }
        }
    }
}

public struct MyColor
{
    public short Red;
    public short Green;
    public short Blue;
    public short Alpha;

    // Make the view brighter.
    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
Imports System.IO.MemoryMappedFiles
Imports System.Runtime.InteropServices

Class Program

    Sub Main()
        Dim offset As Long = &H10000000 ' 256 megabytes
        Dim length As Long = &H20000000 ' 512 megabytes

        ' Create the memory-mapped file.
        Using mmf = MemoryMappedFile.CreateFromFile("c:\ExtremelyLargeImage.data", FileMode.Open, "ImgA")
            ' Create a random access view, from the 256th megabyte (the offset)
            ' to the 768th megabyte (the offset plus length).
            Using accessor = mmf.CreateViewAccessor(offset, length)
                Dim colorSize As Integer = Marshal.SizeOf(GetType(MyColor))
                Dim color As MyColor
                Dim i As Long = 0

                ' Make changes to the view.
                Do While (i < length)
                    accessor.Read(i, color)
                    color.Brighten(10)
                    accessor.Write(i, color)
                    i += colorSize
                Loop
            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 brighter.
    Public Sub Brighten(ByVal value As Short)
        Red = CType(Math.Min(Short.MaxValue, (CType(Red, Integer) + value)), Short)
        Green = CType(Math.Min(Short.MaxValue, (CType(Green, Integer) + value)), Short)
        Blue = CType(Math.Min(Short.MaxValue, (CType(Blue, Integer) + value)), Short)
        Alpha = CType(Math.Min(Short.MaxValue, (CType(Alpha, Integer) + value)), Short)
    End Sub
End Structure

설명

메모리 매핑된 파일을 애플리케이션의 논리 주소 공간에 파일의 콘텐츠를 매핑합니다. 메모리 매핑 파일을 사용하면 메모리를 동시에 관리할 수 있고 검색할 필요 없이 파일에 대한 완전하고 임의로 액세스할 수 있으므로 프로그래머가 매우 큰 파일로 작업할 수 있습니다. 메모리 매핑된 파일은 여러 프로세스에서 공유할 수도 있습니다.

메서드는 CreateFromFile 지정된 경로 또는 FileStream 디스크에 있는 기존 파일의 에서 메모리 매핑된 파일을 만듭니다. 파일이 매핑되지 않으면 변경 내용이 디스크에 자동으로 전파됩니다.

메서드는 CreateNew 디스크의 기존 파일에 매핑되지 않고 IPC(Interprocess 통신)를 위한 공유 메모리를 만드는 데 적합한 메모리 매핑 파일을 만듭니다.

메모리 매핑된 파일은 메모리 매핑된 파일을 다른 프로세스와 공유할 수 있는 선택적 이름과 연결할 수 있습니다.

파일의 일부 보기를 포함하여 메모리 매핑된 파일의 여러 보기를 만들 수 있습니다. 파일의 동일한 부분을 둘 이상의 주소에 매핑하여 동시 메모리를 만들 수 있습니다. 두 보기를 동시에 유지하려면 동일한 메모리 매핑된 파일에서 보기를 만들어야 합니다. 두 개의 뷰를 사용하여 동일한 파일의 두 파일 매핑을 만들면 동시성이 제공되지 않습니다.

속성

SafeMemoryMappedFileHandle

메모리 매핑된 파일의 파일 핸들을 가져옵니다.

메서드

CreateFromFile(FileStream, String, Int64, MemoryMappedFileAccess, HandleInheritability, Boolean)

지정된 액세스 모드, 이름, 상속 및 용량을 사용하여 기존 파일에서 메모리 매핑된 파일을 만듭니다.

CreateFromFile(FileStream, String, Int64, MemoryMappedFileAccess, MemoryMappedFileSecurity, HandleInheritability, Boolean)

디스크의 파일에서 지정된 이름, 용량, 액세스 형식, 보안 권한, 상속 가능성 및 삭제 요구 사항을 가진 메모리 매핑된 파일을 만듭니다.

CreateFromFile(SafeFileHandle, String, Int64, MemoryMappedFileAccess, HandleInheritability, Boolean)

및 지정된 액세스 모드, 이름, 상속 가능성 및 용량을 사용하여 SafeFileHandle 기존 파일에서 메모리 매핑 파일을 만듭니다.

CreateFromFile(String)

디스크의 파일에서 메모리 매핑된 파일을 만듭니다.

CreateFromFile(String, FileMode)

디스크의 파일에서 지정된 액세스 모드를 가진 메모리 매핑된 파일을 만듭니다.

CreateFromFile(String, FileMode, String)

디스크의 파일에서 지정된 액세스 모드와 이름을 가진 메모리 매핑된 파일을 만듭니다.

CreateFromFile(String, FileMode, String, Int64)

디스크의 파일에서 지정된 액세스 모드, 이름 및 용량을 가진 메모리 매핑된 파일을 만듭니다.

CreateFromFile(String, FileMode, String, Int64, MemoryMappedFileAccess)

디스크의 파일에서 지정된 액세스 모드, 이름, 용량 및 액세스 형식을 가진 메모리 매핑된 파일을 만듭니다.

CreateNew(String, Int64)

시스템 메모리에서 지정된 용량을 가진 메모리 매핑된 파일을 만듭니다.

CreateNew(String, Int64, MemoryMappedFileAccess)

시스템 메모리에서 지정된 용량과 액세스 형식을 가진 메모리 매핑된 파일을 만듭니다.

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

지정된 이름, 용량, 액세스 형식, 메모리 할당 옵션 및 상속을 가진 메모리 매핑된 파일을 만듭니다.

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

시스템 메모리에서 지정된 용량, 액세스 형식, 메모리 할당, 보안 권한 및 상속 가능성을 가진 메모리 매핑된 파일을 만듭니다.

CreateOrOpen(String, Int64)

시스템 메모리에서 지정된 이름 및 용량을 가진 메모리 매핑된 파일을 만들거나 엽니다.

CreateOrOpen(String, Int64, MemoryMappedFileAccess)

시스템 메모리에서 지정된 이름, 용량 및 액세스 형식을 가진 메모리 매핑된 파일을 만들거나 엽니다.

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

동일한 이름의 파일이 있는 경우 비어 있는 새 메모리 매핑된 파일을 만들거나 기존의 메모리 매핑된 파일을 엽니다. 기존 파일을 여는 경우 용량, 옵션 및 메모리 인수가 무시됩니다.

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

시스템 메모리에서 지정된 이름, 용량, 액세스 형식, 메모리 할당, 보안 권한 및 상속 가능성을 가진 메모리 매핑된 파일을 만들거나 엽니다.

CreateViewAccessor()

메모리 매핑된 파일의 뷰에 매핑되는 MemoryMappedViewAccessor를 만듭니다.

CreateViewAccessor(Int64, Int64)

지정된 오프셋과 크기를 가지고 메모리 매핑된 파일의 뷰에 매핑되는 MemoryMappedViewAccessor를 만듭니다.

CreateViewAccessor(Int64, Int64, MemoryMappedFileAccess)

지정된 오프셋, 크기 및 액세스 제한을 가지고 메모리 매핑된 파일의 뷰에 매핑되는 MemoryMappedViewAccessor를 만듭니다.

CreateViewStream()

메모리 매핑된 파일의 뷰에 매핑되는 스트림을 만듭니다.

CreateViewStream(Int64, Int64)

지정된 오프셋과 크기를 가지고 메모리 매핑된 파일의 뷰에 매핑되는 스트림을 만듭니다.

CreateViewStream(Int64, Int64, MemoryMappedFileAccess)

지정된 오프셋, 크기 및 액세스 형식을 가지고 메모리 매핑된 파일의 뷰에 매핑되는 스트림을 만듭니다.

Dispose()

MemoryMappedFile에서 사용하는 모든 리소스를 해제합니다.

Dispose(Boolean)

MemoryMappedFile에서 사용하는 관리되지 않는 리소스를 해제하고, 관리되는 리소스를 선택적으로 해제할 수 있습니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetAccessControl()

메모리 매핑된 파일 리소스에 대한 액세스 제어를 가져옵니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
OpenExisting(String)

시스템 메모리에서 지정된 이름을 가진 기존의 메모리 매핑된 파일을 엽니다.

OpenExisting(String, MemoryMappedFileRights)

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

OpenExisting(String, MemoryMappedFileRights, HandleInheritability)

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

SetAccessControl(MemoryMappedFileSecurity)

메모리 매핑된 파일 리소스에 대한 액세스 제어를 설정합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보