MemoryMappedFile.OpenExisting Méthode

Définition

Ouvre un fichier nommé existant mappé en mémoire dans la mémoire système.

Surcharges

OpenExisting(String)

Ouvre un fichier mappé en mémoire existant qui a le nom spécifié dans la mémoire système.

OpenExisting(String, MemoryMappedFileRights)

Ouvre un fichier mappé en mémoire existant qui a le nom et les droits d'accès spécifiés dans la mémoire système.

OpenExisting(String, MemoryMappedFileRights, HandleInheritability)

Ouvre un fichier mappé en mémoire existant qui a le nom, les droits d'accès et les règles d'héritage spécifiés dans la mémoire système.

OpenExisting(String)

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

Ouvre un fichier mappé en mémoire existant qui a le nom spécifié dans la mémoire système.

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

Paramètres

mapName
String

Nom du fichier mappé en mémoire.

Retours

Fichier mappé en mémoire qui porte le nom spécifié.

Attributs

Exceptions

mapName a la valeur null.

mapName est une chaîne vide.

Le fichier spécifié pour mapName n’existe pas.

Exemples

Ouverture d’un fichier de Memory-Mapped persistant

L’exemple suivant ouvre un fichier mappé en mémoire nommé ImgA qui a déjà été créé à partir d’un fichier sur disque (comme indiqué dans l’exemple de la CreateFromFile(String) méthode ).

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

Ouverture d’un fichier de Memory-Mapped non persistant

L’exemple suivant ouvre un fichier mappé en mémoire utilisé pour la communication entre processus. Cet exemple de code fait partie d’un exemple plus grand fourni pour la CreateNew(String, Int64) méthode .

Remarques

Le fichier mappé en mémoire peut être un fichier mappé en mémoire persistant (associé à un fichier sur disque) ou non persistant.

Voir aussi

S’applique à

OpenExisting(String, MemoryMappedFileRights)

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

Ouvre un fichier mappé en mémoire existant qui a le nom et les droits d'accès spécifiés dans la mémoire système.

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

Paramètres

mapName
String

Nom du fichier mappé en mémoire à ouvrir.

desiredAccessRights
MemoryMappedFileRights

L'une des valeurs d'énumération qui spécifie les droits d'accès à appliquer au fichier mappé en mémoire.

Retours

Fichier mappé en mémoire qui possède les caractéristiques spécifiées.

Attributs

Exceptions

mapName a la valeur null.

mapName est une chaîne vide.

desiredAccessRights n’est pas une valeur d’énumération MemoryMappedFileRights valide.

Le fichier spécifié pour mapName n’existe pas.

Voir aussi

S’applique à

OpenExisting(String, MemoryMappedFileRights, HandleInheritability)

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

Ouvre un fichier mappé en mémoire existant qui a le nom, les droits d'accès et les règles d'héritage spécifiés dans la mémoire système.

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

Paramètres

mapName
String

Nom du fichier mappé en mémoire à ouvrir.

desiredAccessRights
MemoryMappedFileRights

L'une des valeurs d'énumération qui spécifie les droits d'accès à appliquer au fichier mappé en mémoire.

inheritability
HandleInheritability

L'une des valeurs d'énumération qui spécifie si un processus enfant peut hériter d'un handle au fichier mappé en mémoire. La valeur par défaut est None.

Retours

Fichier mappé en mémoire qui possède les caractéristiques spécifiées.

Attributs

Exceptions

mapName a la valeur null.

mapName est une chaîne vide.

desiredAccessRights n’est pas une valeur d’énumération MemoryMappedFileRights valide.

- ou -

inheritability n’est pas une valeur d’énumération HandleInheritability valide.

L’accès demandé n’est pas valide pour le fichier mappé en mémoire.

Le fichier spécifié pour mapName n’existe pas.

Voir aussi

S’applique à