MemoryMappedFile.CreateNew 메서드

정의

시스템 메모리에 메모리 매핑된 파일을 만듭니다.

오버로드

CreateNew(String, Int64)

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

CreateNew(String, Int64, MemoryMappedFileAccess)

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

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

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

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

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

CreateNew(String, Int64)

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

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

public:
 static System::IO::MemoryMappedFiles::MemoryMappedFile ^ CreateNew(System::String ^ mapName, long capacity);
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateNew (string? mapName, long capacity);
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateNew (string mapName, long capacity);
static member CreateNew : string * int64 -> System.IO.MemoryMappedFiles.MemoryMappedFile
Public Shared Function CreateNew (mapName As String, capacity As Long) As MemoryMappedFile

매개 변수

mapName
String

메모리 매핑된 파일에 할당할 이름 또는 프로세스 간에 공유하지 않으려는 MemoryMappedFile에 대한 null입니다.

capacity
Int64

메모리 매핑된 파일에 할당할 최대 크기(바이트)입니다.

반환

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

예외

mapName이 빈 문자열인 경우

capacity가 0보다 작거나 같습니다.

.NET Core 및 .NET 5 이상만 해당: 명명된 메모리 매핑 파일(즉, nullmapName이 아닌 )이 있는 메서드에 대한 호출 CreateNew 은 Windows 운영 체제에서만 지원됩니다.

예제

다음 예제에서는 작성 하는 세 가지 별도 프로세스 (콘솔 애플리케이션)로 이루어져 Boolean 메모리 매핑된 파일에는 값입니다. 다음 작업 시퀀스가 발생합니다.

  1. 프로세스 A는 메모리 매핑된 파일을 만들고 값을 씁니다.

  2. 프로세스 B는 메모리 매핑된 파일을 열고 값을 씁니다.

  3. 프로세스 C는 메모리 매핑된 파일을 열고 값을 씁니다.

  4. 프로세스 A는 메모리 매핑된 파일의 값을 읽고 표시합니다.

  5. 프로세스 A가 메모리 매핑된 파일로 완료되면 가비지 수집에 의해 파일이 즉시 회수됩니다.

이 예제를 실행하려면 다음을 수행합니다.

  1. 애플리케이션을 컴파일하고 세 개의 명령 창을 엽니다.

  2. 첫 번째 명령 창에서 프로세스 A를 실행합니다.

  3. 두 번째 명령 창에서 프로세스 B를 실행합니다.

  4. 프로세스 A로 돌아가서 Enter 키를 누릅니다.

  5. 세 번째 명령 창에서 프로세스 C를 실행합니다.

  6. 프로세스 A로 돌아가서 Enter 키를 누릅니다.

프로세스 A의 출력은 다음과 같습니다.

Start Process B and press ENTER to continue.
Start Process C and press ENTER to continue.
Process A says: True
Process B says: False
Process C says: True

프로세스 A

using System;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Threading;

class Program
{
    // Process A:
    static void Main(string[] args)
    {
        using (MemoryMappedFile mmf = MemoryMappedFile.CreateNew("testmap", 10000))
        {
            bool mutexCreated;
            Mutex mutex = new Mutex(true, "testmapmutex", out mutexCreated);
            using (MemoryMappedViewStream stream = mmf.CreateViewStream())
            {
                BinaryWriter writer = new BinaryWriter(stream);
                writer.Write(1);
            }
            mutex.ReleaseMutex();

            Console.WriteLine("Start Process B and press ENTER to continue.");
            Console.ReadLine();

            Console.WriteLine("Start Process C and press ENTER to continue.");
            Console.ReadLine();

            mutex.WaitOne();
            using (MemoryMappedViewStream stream = mmf.CreateViewStream())
            {
                BinaryReader reader = new BinaryReader(stream);
                Console.WriteLine("Process A says: {0}", reader.ReadBoolean());
                Console.WriteLine("Process B says: {0}", reader.ReadBoolean());
                Console.WriteLine("Process C says: {0}", reader.ReadBoolean());
            }
            mutex.ReleaseMutex();
        }
    }
}
Imports System.IO
Imports System.IO.MemoryMappedFiles
Imports System.Threading

Module Module1

    ' Process A:
    Sub Main()
        Using mmf As MemoryMappedFile = MemoryMappedFile.CreateNew("testmap", 10000)
            Dim mutexCreated As Boolean
            Dim mTex As Mutex = New Mutex(True, "testmapmutex", mutexCreated)
            Using Stream As MemoryMappedViewStream = mmf.CreateViewStream()
                Dim writer As BinaryWriter = New BinaryWriter(Stream)
                writer.Write(1)
            End Using
            mTex.ReleaseMutex()
            Console.WriteLine("Start Process B and press ENTER to continue.")
            Console.ReadLine()

            Console.WriteLine("Start Process C and press ENTER to continue.")
            Console.ReadLine()

            mTex.WaitOne()
            Using Stream As MemoryMappedViewStream = mmf.CreateViewStream()
                Dim reader As BinaryReader = New BinaryReader(Stream)
                Console.WriteLine("Process A says: {0}", reader.ReadBoolean())
                Console.WriteLine("Process B says: {0}", reader.ReadBoolean())
                Console.WriteLine("Process C says: {0}", reader.ReadBoolean())
            End Using
            mTex.ReleaseMutex()

        End Using

    End Sub

End Module

프로세스 B

using System;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Threading;

class Program
{
    // Process B:
    static void Main(string[] args)
    {
        try
        {
            using (MemoryMappedFile mmf = MemoryMappedFile.OpenExisting("testmap"))
            {

                Mutex mutex = Mutex.OpenExisting("testmapmutex");
                mutex.WaitOne();

                using (MemoryMappedViewStream stream = mmf.CreateViewStream(1, 0))
                {
                    BinaryWriter writer = new BinaryWriter(stream);
                    writer.Write(0);
                }
                mutex.ReleaseMutex();
            }
        }
        catch (FileNotFoundException)
        {
            Console.WriteLine("Memory-mapped file does not exist. Run Process A first.");
        }
    }
}
Imports System.IO
Imports System.IO.MemoryMappedFiles
Imports System.Threading

Module Module1
    ' Process B:
    Sub Main()
        Try
            Using mmf As MemoryMappedFile = MemoryMappedFile.OpenExisting("testmap")
                Dim mTex As Mutex = Mutex.OpenExisting("testmapmutex")
                mTex.WaitOne()
                Using Stream As MemoryMappedViewStream = mmf.CreateViewStream(1, 0)
                    Dim writer As BinaryWriter = New BinaryWriter(Stream)
                    writer.Write(0)
                End Using
                mTex.ReleaseMutex()
            End Using
        Catch noFile As FileNotFoundException
            Console.WriteLine("Memory-mapped file does not exist. Run Process A first." & vbCrLf & noFile.Message)
        End Try

    End Sub

End Module

프로세스 C

using System;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Threading;

class Program
{
    // Process C:
    static void Main(string[] args)
    {
        try
        {
            using (MemoryMappedFile mmf = MemoryMappedFile.OpenExisting("testmap"))
            {

                Mutex mutex = Mutex.OpenExisting("testmapmutex");
                mutex.WaitOne();

                using (MemoryMappedViewStream stream = mmf.CreateViewStream(2, 0))
                {
                    BinaryWriter writer = new BinaryWriter(stream);
                    writer.Write(1);
                }
                mutex.ReleaseMutex();
            }
        }
        catch (FileNotFoundException)
        {
            Console.WriteLine("Memory-mapped file does not exist. Run Process A first, then B.");
        }
    }
}
Imports System.IO
Imports System.IO.MemoryMappedFiles
Imports System.Threading

Module Module1
    ' Process C:
    Sub Main()
        Try
            Using mmf As MemoryMappedFile = MemoryMappedFile.OpenExisting("testmap")
                Dim mTex As Mutex = Mutex.OpenExisting("testmapmutex")
                mTex.WaitOne()
                Using Stream As MemoryMappedViewStream = mmf.CreateViewStream(2, 0)
                    Dim writer As BinaryWriter = New BinaryWriter(Stream)
                    writer.Write(1)
                End Using
                mTex.ReleaseMutex()
            End Using
        Catch noFile As FileNotFoundException
            Console.WriteLine("Memory-mapped file does not exist. Run Process A first, then B." & vbCrLf & noFile.Message)
        End Try

    End Sub

End Module

설명

이 메서드를 사용하여 프로세스 간에 데이터를 공유하는 데 사용할 수 있는 메모리 매핑된 파일(즉, 디스크의 파일과 연결되지 않음)을 만듭니다.

추가 정보

적용 대상

CreateNew(String, Int64, MemoryMappedFileAccess)

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

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

public:
 static System::IO::MemoryMappedFiles::MemoryMappedFile ^ CreateNew(System::String ^ mapName, long capacity, System::IO::MemoryMappedFiles::MemoryMappedFileAccess access);
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateNew (string? mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access);
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateNew (string mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access);
static member CreateNew : string * int64 * System.IO.MemoryMappedFiles.MemoryMappedFileAccess -> System.IO.MemoryMappedFiles.MemoryMappedFile
Public Shared Function CreateNew (mapName As String, capacity As Long, access As MemoryMappedFileAccess) As MemoryMappedFile

매개 변수

mapName
String

메모리 매핑된 파일에 할당할 이름 또는 프로세스 간에 공유하지 않으려는 MemoryMappedFile에 대한 null입니다.

capacity
Int64

메모리 매핑된 파일에 할당할 최대 크기(바이트)입니다.

access
MemoryMappedFileAccess

메모리 매핑된 파일에 허용되는 액세스 형식을 지정하는 열거형 값 중 하나입니다. 기본값은 ReadWrite입니다.

반환

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

예외

mapName이 빈 문자열인 경우

또는

accessWrite 열거형 값이 있는 쓰기 전용으로 설정됩니다.

capacity가 0보다 작거나 같습니다.

또는

access가 유효한 MemoryMappedFileAccess 열거형 값이 아닙니다.

.NET Core 및 .NET 5 이상만 해당: 명명된 메모리 매핑 파일(즉, nullmapName이 아닌 )이 있는 메서드에 대한 호출 CreateNew 은 Windows 운영 체제에서만 지원됩니다.

설명

이 메서드를 사용하여 프로세스 간에 데이터를 공유하는 데 사용할 수 있는 메모리 매핑된 파일(즉, 디스크의 파일과 연결되지 않음)을 만듭니다.

추가 정보

적용 대상

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

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

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

public:
 static System::IO::MemoryMappedFiles::MemoryMappedFile ^ CreateNew(System::String ^ mapName, long capacity, System::IO::MemoryMappedFiles::MemoryMappedFileAccess access, System::IO::MemoryMappedFiles::MemoryMappedFileOptions options, System::IO::HandleInheritability inheritability);
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateNew (string? mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access, System.IO.MemoryMappedFiles.MemoryMappedFileOptions options, System.IO.HandleInheritability inheritability);
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateNew (string mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access, System.IO.MemoryMappedFiles.MemoryMappedFileOptions options, System.IO.HandleInheritability inheritability);
static member CreateNew : string * int64 * System.IO.MemoryMappedFiles.MemoryMappedFileAccess * System.IO.MemoryMappedFiles.MemoryMappedFileOptions * System.IO.HandleInheritability -> System.IO.MemoryMappedFiles.MemoryMappedFile
Public Shared Function CreateNew (mapName As String, capacity As Long, access As MemoryMappedFileAccess, options As MemoryMappedFileOptions, inheritability As HandleInheritability) As MemoryMappedFile

매개 변수

mapName
String

메모리 매핑된 파일에 할당할 이름 또는 프로세스 간에 공유하지 않으려는 MemoryMappedFile에 대한 null입니다.

capacity
Int64

메모리 매핑된 파일에 할당할 최대 크기(바이트)입니다.

access
MemoryMappedFileAccess

메모리 매핑된 파일에 허용되는 액세스 형식을 지정하는 열거형 값 중 하나입니다. 기본값은 ReadWrite입니다.

options
MemoryMappedFileOptions

메모리 매핑된 파일에 대한 메모리 할당 옵션을 지정하는 열거형 값의 비트 조합입니다.

inheritability
HandleInheritability

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

반환

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

예외

mapName이 빈 문자열인 경우

또는

accessWrite 열거형 값이 있는 쓰기 전용으로 설정됩니다.

capacity가 0보다 작거나 같습니다.

또는

access가 유효한 MemoryMappedFileAccess 열거형 값이 아닙니다.

또는

inheritability는 유효한 HandleInheritability 값이 아닙니다.

.NET Core 및 .NET 5 이상만 해당: 명명된 메모리 매핑 파일(즉, nullmapName이 아닌 )이 있는 메서드에 대한 호출 CreateNew 은 Windows 운영 체제에서만 지원됩니다.

적용 대상

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

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

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

매개 변수

mapName
String

메모리 매핑된 파일에 할당할 이름 또는 프로세스 간에 공유하지 않으려는 MemoryMappedFile에 대한 null입니다.

capacity
Int64

메모리 매핑된 파일에 할당할 최대 크기(바이트)입니다.

access
MemoryMappedFileAccess

메모리 매핑된 파일에 허용되는 액세스 형식을 지정하는 열거형 값 중 하나입니다. 기본값은 ReadWrite입니다.

options
MemoryMappedFileOptions

메모리 매핑된 파일에 대한 메모리 할당 옵션을 지정하는 열거형 값의 비트 조합입니다.

memoryMappedFileSecurity
MemoryMappedFileSecurity

메모리 매핑된 파일에 대한 파일 액세스 및 작업에 부여할 수 있는 권한입니다.

이 매개 변수는 null일 수 있습니다.

inheritability
HandleInheritability

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

반환

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

특성

예외

mapName이 빈 문자열인 경우

또는

accessWrite 열거형 값이 있는 쓰기 전용으로 설정됩니다.

capacity가 0보다 작거나 같습니다.

또는

access가 유효한 MemoryMappedFileAccess 열거형 값이 아닙니다.

또는

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

설명

이 메서드를 사용하여 프로세스 간에 데이터를 공유하는 데 사용할 수 있는 메모리 매핑된 파일(즉, 디스크의 파일과 연결되지 않음)을 만듭니다.

추가 정보

적용 대상