MemoryMappedFile.CreateViewAccessor MemoryMappedFile.CreateViewAccessor MemoryMappedFile.CreateViewAccessor MemoryMappedFile.CreateViewAccessor Method

定義

建立對應於記憶體對應檔檢視的 MemoryMappedViewAccessorCreates a MemoryMappedViewAccessor that maps to a view of the memory-mapped file.

多載

CreateViewAccessor() CreateViewAccessor() CreateViewAccessor() CreateViewAccessor()

建立對應於記憶體對應檔檢視的 MemoryMappedViewAccessorCreates a MemoryMappedViewAccessor that maps to a view of the memory-mapped file.

CreateViewAccessor(Int64, Int64) CreateViewAccessor(Int64, Int64) CreateViewAccessor(Int64, Int64) CreateViewAccessor(Int64, Int64)

建立 MemoryMappedViewAccessor,此存取子可對應到記憶體對應檔案的檢視,並且有指定的位移和大小。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) CreateViewAccessor(Int64, Int64, MemoryMappedFileAccess) CreateViewAccessor(Int64, Int64, MemoryMappedFileAccess) CreateViewAccessor(Int64, Int64, MemoryMappedFileAccess)

建立 MemoryMappedViewAccessor,此存取子可對應到記憶體對應檔案的檢視,並且有指定位移、大小和存取限制。Creates a MemoryMappedViewAccessor that maps to a view of the memory-mapped file, and that has the specified offset, size, and access restrictions.

CreateViewAccessor() CreateViewAccessor() CreateViewAccessor() CreateViewAccessor()

建立對應於記憶體對應檔檢視的 MemoryMappedViewAccessorCreates a MemoryMappedViewAccessor that maps to a view of the memory-mapped file.

public:
 System::IO::MemoryMappedFiles::MemoryMappedViewAccessor ^ CreateViewAccessor();
public System.IO.MemoryMappedFiles.MemoryMappedViewAccessor CreateViewAccessor ();
member this.CreateViewAccessor : unit -> System.IO.MemoryMappedFiles.MemoryMappedViewAccessor
Public Function CreateViewAccessor () As MemoryMappedViewAccessor

傳回

記憶體隨機存取區塊。A randomly accessible block of memory.

例外狀況

未授權存取記憶體對應檔案。Access to the memory-mapped file is unauthorized.

備註

您可以使用這個方法傳回的視圖, 隨機存取記憶體對應檔。You can use the view returned by this method for random access to a memory-mapped file.

另請參閱

CreateViewAccessor(Int64, Int64) CreateViewAccessor(Int64, Int64) CreateViewAccessor(Int64, Int64) CreateViewAccessor(Int64, Int64)

建立 MemoryMappedViewAccessor,此存取子可對應到記憶體對應檔案的檢視,並且有指定的位移和大小。Creates a MemoryMappedViewAccessor that maps to a view of the memory-mapped file, and that has the specified offset and size.

public:
 System::IO::MemoryMappedFiles::MemoryMappedViewAccessor ^ CreateViewAccessor(long offset, long size);
public System.IO.MemoryMappedFiles.MemoryMappedViewAccessor CreateViewAccessor (long offset, long size);
member this.CreateViewAccessor : int64 * int64 -> System.IO.MemoryMappedFiles.MemoryMappedViewAccessor
Public Function CreateViewAccessor (offset As Long, size As Long) As MemoryMappedViewAccessor

參數

offset
Int64 Int64 Int64 Int64

檢視會在此處開始的位元組。The byte at which to start the view.

size
Int64 Int64 Int64 Int64

檢視的大小。The size of the view. 指定 0 (零),建立在 offset 開始,而大約在記憶體對應檔結尾結束的檢視。Specify 0 (zero) to create a view that starts at offset and ends approximately at the end of the memory-mapped file.

傳回

記憶體隨機存取區塊。A randomly accessible block of memory.

例外狀況

offsetsize 為負值。offset or size is a negative value.

-或--or- size 大於邏輯位址空間。size is greater than the logical address space.

未授權存取記憶體對應檔案。Access to the memory-mapped file is unauthorized.

發生 I/O 錯誤。An I/O error occurred.

範例

下列範例會建立記憶體對應檔案的視圖, 並加以編輯。The following example creates a view of a memory-mapped file and edits it. 這個程式碼範例是針對MemoryMappedFile類別提供之較大範例的一部分。This code example is part of a larger example provided for the MemoryMappedFile class.

// 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);
    }
}
' 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

備註

您可以使用這個方法傳回的視圖, 隨機存取記憶體對應檔。You can use the view returned by this method for random access to a memory-mapped file.

若要建立記憶體對應檔案的完整視圖, 請為size參數指定 0 (零)。To create a complete view of the memory-mapped file, specify 0 (zero) for the size parameter. 如果您這樣做, 則此視圖的大小可能會小於或大於磁片上的來源檔案大小。If you do this, the size of the view might be smaller or larger than the size of the source file on disk. 這是因為 views 是以系統頁面的單位提供, 而且視圖的大小會無條件進位到下一個系統頁面大小。This is because views are provided in units of system pages, and the size of the view is rounded up to the next system page size.

另請參閱

CreateViewAccessor(Int64, Int64, MemoryMappedFileAccess) CreateViewAccessor(Int64, Int64, MemoryMappedFileAccess) CreateViewAccessor(Int64, Int64, MemoryMappedFileAccess) CreateViewAccessor(Int64, Int64, MemoryMappedFileAccess)

建立 MemoryMappedViewAccessor,此存取子可對應到記憶體對應檔案的檢視,並且有指定位移、大小和存取限制。Creates a MemoryMappedViewAccessor that maps to a view of the memory-mapped file, and that has the specified offset, size, and access restrictions.

public:
 System::IO::MemoryMappedFiles::MemoryMappedViewAccessor ^ CreateViewAccessor(long offset, long size, System::IO::MemoryMappedFiles::MemoryMappedFileAccess access);
[System.Security.SecurityCritical]
public System.IO.MemoryMappedFiles.MemoryMappedViewAccessor CreateViewAccessor (long offset, long size, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access);
member this.CreateViewAccessor : int64 * int64 * System.IO.MemoryMappedFiles.MemoryMappedFileAccess -> System.IO.MemoryMappedFiles.MemoryMappedViewAccessor
Public Function CreateViewAccessor (offset As Long, size As Long, access As MemoryMappedFileAccess) As MemoryMappedViewAccessor

參數

offset
Int64 Int64 Int64 Int64

檢視會在此處開始的位元組。The byte at which to start the view.

size
Int64 Int64 Int64 Int64

檢視的大小。The size of the view. 指定 0 (零),建立在 offset 開始,而大約在記憶體對應檔結尾結束的檢視。Specify 0 (zero) to create a view that starts at offset and ends approximately at the end of the memory-mapped file.

access
MemoryMappedFileAccess MemoryMappedFileAccess MemoryMappedFileAccess MemoryMappedFileAccess

其中一個列舉值,指定記憶體對應檔允許的存取類型。One of the enumeration values that specifies the type of access allowed to the memory-mapped file. 預設為 ReadWriteThe default is ReadWrite.

傳回

記憶體隨機存取區塊。A randomly accessible block of memory.

例外狀況

offsetsize 為負值。offset or size is a negative value.

-或--or- size 大於邏輯位址空間。size is greater than the logical address space.

access 是無效的記憶體對應檔案。access is invalid for the memory-mapped file.

發生 I/O 錯誤。An I/O error occurred.

備註

您可以使用這個方法傳回的視圖, 隨機存取記憶體對應檔。You can use the view returned by this method for random access to a memory-mapped file.

若要建立記憶體對應檔案的完整視圖, 請為size參數指定 0 (零)。To create a complete view of the memory-mapped file, specify 0 (zero) for the size parameter. 如果您這樣做, 則此視圖的大小可能會小於或大於磁片上的來源檔案大小。If you do this, the size of the view might be smaller or larger than the size of the source file on disk. 這是因為 views 是以系統頁面的單位提供, 而且視圖的大小會無條件進位到下一個系統頁面大小。This is because views are provided in units of system pages, and the size of the view is rounded up to the next system page size.

安全性

SecurityPermission
用於存取未受管理的程式碼。for access to unmanaged code. 關聯的列舉型別:UnmanagedCodeAssociated enumeration: UnmanagedCode.

另請參閱

適用於