MemoryMappedFile Sınıf

Tanım

Bellek eşlemeli bir dosyayı temsil eder.Represents a memory-mapped file.

public ref class MemoryMappedFile : IDisposable
public class MemoryMappedFile : IDisposable
type MemoryMappedFile = class
    interface IDisposable
Public Class MemoryMappedFile
Implements IDisposable
Devralma
MemoryMappedFile
Uygulamalar

Örnekler

Aşağıdaki örnek, son derece büyük bir dosyanın bir bölümünün bellek eşlemeli bir görünümünü oluşturur ve bir kısmını yönetir.The following example creates a memory-mapped view of a part of an extremely large file and manipulates a portion of it.

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

Açıklamalar

Bellek eşlemeli bir dosya, bir dosyanın içeriğini bir uygulamanın mantıksal adres alanına eşler.A memory-mapped file maps the contents of a file to an application's logical address space. Bellek eşlemeli dosyalar, programcılar çok büyük dosyalarla çalışabildiklerinden, bellek eşzamanlı olarak yönetilebildiğinden ve arama gerekmeden bir dosyaya tam ve rastgele erişime izin veriyor.Memory-mapped files enable programmers to work with extremely large files because memory can be managed concurrently, and they allow complete, random access to a file without the need for seeking. Ayrıca, bellek eşlemeli dosyalar birden çok işlem arasında paylaşılabilir.Memory-mapped files can also be shared across multiple processes.

CreateFromFileYöntemler, belirtilen bir yoldan veya FileStream diskte var olan bir dosyadan bellek eşlemeli bir dosya oluşturur.The CreateFromFile methods create a memory-mapped file from a specified path or a FileStream of an existing file on disk. Dosya eşlenme yapıldığında değişiklikler otomatik olarak diske yayılır.Changes are automatically propagated to disk when the file is unmapped.

CreateNewYöntemler, diskte var olan bir dosyayla eşlenmemiş ve işlemler arası iletişim (IPC) için paylaşılan bellek oluşturmak üzere uygun olan bellek eşlemeli bir dosya oluşturur.The CreateNew methods create a memory-mapped file that is not mapped to an existing file on disk; and are suitable for creating shared memory for interprocess communication (IPC).

Bellek eşlemeli bir dosya, bellek eşlemeli dosyanın diğer işlemlerle paylaşılmasına izin veren bir isteğe bağlı adla ilişkilendirilebilir.A memory-mapped file can be associated with an optional name that allows the memory-mapped file to be shared with other processes.

Dosya bölümlerinin görünümleri dahil olmak üzere, bellek eşlemeli dosyanın birden çok görünümünü oluşturabilirsiniz.You can create multiple views of the memory-mapped file, including views of parts of the file. Aynı anda bir dosyanın aynı bölümünü birden fazla adrese eşleyebilir ve eşzamanlı bellek oluşturabilirsiniz.You can map the same part of a file to more than one address to create concurrent memory. İki görünümün eşzamanlı kalması için aynı bellek eşlemeli dosyadan oluşturulması gerekir.For two views to remain concurrent, they have to be created from the same memory-mapped file. İki görünümle aynı dosyanın iki dosya eşlemesi oluşturmak eşzamanlılık sağlamaz.Creating two file mappings of the same file with two views does not provide concurrency.

Özellikler

SafeMemoryMappedFileHandle

Bellek eşlemeli bir dosyanın dosya tanıtıcısını alır.Gets the file handle of a memory-mapped file.

Yöntemler

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

Mevcut bir dosyadan, belirtilen erişim modu, ad, inheritability ve kapasiteye sahip bir bellek eşlemeli dosya oluşturur.Creates a memory-mapped file from an existing file with the specified access mode, name, inheritability, and capacity.

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

Disk üzerindeki bir dosyanın belirtilen adı, kapasitesi, erişim türü, güvenlik izinleri, inheritability ve aktiften çıkarma gereksinimini içeren bir bellek eşlemeli dosya oluşturur.Creates a memory-mapped file that has the specified name, capacity, access type, security permissions, inheritability, and disposal requirement from a file on disk.

CreateFromFile(String)

Diskteki bir dosyadan bellek eşlemeli bir dosya oluşturur.Creates a memory-mapped file from a file on disk.

CreateFromFile(String, FileMode)

Disk üzerindeki bir dosyadan belirtilen erişim moduna sahip, bellek eşlemeli bir dosya oluşturur.Creates a memory-mapped file that has the specified access mode from a file on disk.

CreateFromFile(String, FileMode, String)

Disk üzerindeki bir dosyadan belirtilen erişim moduna ve adına sahip bir bellek eşlemeli dosya oluşturur.Creates a memory-mapped file that has the specified access mode and name from a file on disk.

CreateFromFile(String, FileMode, String, Int64)

Disk üzerindeki bir dosyanın belirtilen erişim modu, adı ve kapasitesine sahip bir bellek eşlemeli dosya oluşturur.Creates a memory-mapped file that has the specified access mode, name, and capacity from a file on disk.

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

Disk üzerindeki bir dosyadan belirtilen erişim modu, adı, kapasitesi ve erişim türüne sahip bellek eşlemeli bir dosya oluşturur.Creates a memory-mapped file that has the specified access mode, name, capacity, and access type from a file on disk.

CreateNew(String, Int64)

Sistem belleğinde belirtilen kapasiteye sahip bellek eşlemeli bir dosya oluşturur.Creates a memory-mapped file that has the specified capacity in system memory.

CreateNew(String, Int64, MemoryMappedFileAccess)

Sistem belleğinde belirtilen kapasite ve erişim türüne sahip bir bellek eşlemeli dosya oluşturur.Creates a memory-mapped file that has the specified capacity and access type in system memory.

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

Belirtilen ada, kapasiteye, erişim türüne, bellek ayırma seçeneklerine ve inheritability sahip olan bellek eşlemeli bir dosya oluşturur.Creates a memory-mapped file that has the specified name, capacity, access type, memory allocation options and inheritability.

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

Sistem belleğindeki belirtilen kapasiteye, erişim türüne, bellek ayırmaya, güvenlik izinlerine ve inheritability sahip bir bellek eşlemeli dosya oluşturur.Creates a memory-mapped file that has the specified capacity, access type, memory allocation, security permissions, and inheritability in system memory.

CreateOrOpen(String, Int64)

Sistem belleğinde belirtilen ad ve kapasiteye sahip bir bellek eşlemeli dosya oluşturur veya açar.Creates or opens a memory-mapped file that has the specified name and capacity in system memory.

CreateOrOpen(String, Int64, MemoryMappedFileAccess)

Sistem belleğinde belirtilen ada, kapasiteye ve erişim türüne sahip bir bellek eşlemeli dosya oluşturur veya açar.Creates or opens a memory-mapped file that has the specified name, capacity and access type in system memory.

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

Yeni bir boş bellek eşlenmiş dosya oluşturur veya aynı ada sahip varsa, var olan bir bellek eşlemeli dosyayı açar.Creates a new empty memory mapped file or opens an existing memory mapped file if one exists with the same name. Var olan bir dosyayı açarsanız, kapasite, Seçenekler ve bellek bağımsız değişkenleri göz ardı edilir.If opening an existing file, the capacity, options, and memory arguments will be ignored.

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

Belirtilen adı, kapasiteyi, erişim türünü, bellek ayırmayı, güvenlik izinlerini ve inheritability sistem belleğinde bulunan, bellek eşlemeli bir dosya oluşturur veya açar.Creates or opens a memory-mapped file that has the specified name, capacity, access type, memory allocation, security permissions, and inheritability in system memory.

CreateViewAccessor()

MemoryMappedViewAccessorBellek eşlemeli dosyanın bir görünümüyle eşleşen bir oluşturur.Creates a MemoryMappedViewAccessor that maps to a view of the memory-mapped file.

CreateViewAccessor(Int64, Int64)

MemoryMappedViewAccessorBellek eşlemeli dosyanın bir görünümüne eşleyen ve belirtilen uzaklığa ve boyuta sahip olan bir oluşturur.Creates a MemoryMappedViewAccessor that maps to a view of the memory-mapped file, and that has the specified offset and size.

CreateViewAccessor(Int64, Int64, MemoryMappedFileAccess)

MemoryMappedViewAccessor, Bellek eşlemeli dosyanın bir görünümüne eşlenen ve belirtilen uzaklığa, boyuta ve erişim kısıtlamalarına sahip bir oluşturur.Creates a MemoryMappedViewAccessor that maps to a view of the memory-mapped file, and that has the specified offset, size, and access restrictions.

CreateViewStream()

Bellek eşlemeli dosyanın bir görünümüyle eşleşen bir akış oluşturur.Creates a stream that maps to a view of the memory-mapped file.

CreateViewStream(Int64, Int64)

Bellek eşlemeli dosyanın bir görünümüyle eşleşen ve belirtilen uzaklığa ve boyuta sahip bir akış oluşturur.Creates a stream that maps to a view of the memory-mapped file, and that has the specified offset and size.

CreateViewStream(Int64, Int64, MemoryMappedFileAccess)

Bellek eşlemeli dosyanın bir görünümüyle eşleşen ve belirtilen uzaklığa, boyuta ve erişim türüne sahip bir akış oluşturur.Creates a stream that maps to a view of the memory-mapped file, and that has the specified offset, size, and access type.

Dispose()

MemoryMappedFile tarafından kullanılan tüm kaynakları serbest bırakır.Releases all resources used by the MemoryMappedFile.

Dispose(Boolean)

MemoryMappedFile tarafından kullanılan yönetilmeyen kaynakları serbest bırakır ve yönetilen kaynakları isteğe bağlı olarak serbest bırakır.Releases the unmanaged resources used by the MemoryMappedFile and optionally releases the managed resources.

Equals(Object)

Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler.Determines whether the specified object is equal to the current object.

(Devralındığı yer: Object)
GetAccessControl()

Bellek eşlemeli dosya kaynağına erişim denetimini alır.Gets the access control to the memory-mapped file resource.

GetHashCode()

Varsayılan karma işlevi olarak işlev görür.Serves as the default hash function.

(Devralındığı yer: Object)
GetType()

TypeGeçerli örneği alır.Gets the Type of the current instance.

(Devralındığı yer: Object)
MemberwiseClone()

Geçerli bir basit kopyasını oluşturur Object .Creates a shallow copy of the current Object.

(Devralındığı yer: Object)
OpenExisting(String)

Sistem belleğinde belirtilen ada sahip mevcut bir bellek eşlemeli dosyayı açar.Opens an existing memory-mapped file that has the specified name in system memory.

OpenExisting(String, MemoryMappedFileRights)

Sistem belleğinde belirtilen ad ve erişim haklarına sahip mevcut bir bellek eşlemeli dosyayı açar.Opens an existing memory-mapped file that has the specified name and access rights in system memory.

OpenExisting(String, MemoryMappedFileRights, HandleInheritability)

Belirtilen ada, erişim haklarına ve inheritability sistem belleğine sahip mevcut bir bellek eşlemeli dosyayı açar.Opens an existing memory-mapped file that has the specified name, access rights, and inheritability in system memory.

SetAccessControl(MemoryMappedFileSecurity)

Erişim denetimini bellek eşlemeli dosya kaynağına ayarlar.Sets the access control to the memory-mapped file resource.

ToString()

Geçerli nesneyi temsil eden dizeyi döndürür.Returns a string that represents the current object.

(Devralındığı yer: Object)

Şunlara uygulanır