MemoryMappedFile.CreateViewStream MemoryMappedFile.CreateViewStream MemoryMappedFile.CreateViewStream MemoryMappedFile.CreateViewStream Method

定義

建立對應於記憶體對應檔檢視的資料流。Creates a stream that maps to a view of the memory-mapped file.

多載

CreateViewStream() CreateViewStream() CreateViewStream() CreateViewStream()

建立對應於記憶體對應檔檢視的資料流。Creates a stream that maps to a view of the memory-mapped file.

CreateViewStream(Int64, Int64) CreateViewStream(Int64, Int64) CreateViewStream(Int64, Int64) CreateViewStream(Int64, Int64)

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

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

CreateViewStream() CreateViewStream() CreateViewStream() CreateViewStream()

建立對應於記憶體對應檔檢視的資料流。Creates a stream that maps to a view of the memory-mapped file.

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

傳回

例外狀況

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

範例

下列範例會建立資料流程, 並將值寫入其中。The following example creates a stream and writes a value to it. 這個程式碼範例是針對方法所CreateNew提供之較大範例的一部分。This code example is part of a larger example provided for the CreateNew method.

using (MemoryMappedViewStream stream = mmf.CreateViewStream())
{
    BinaryWriter writer = new BinaryWriter(stream);
    writer.Write(1);
}
Using Stream As MemoryMappedViewStream = mmf.CreateViewStream()
    Dim writer As BinaryWriter = New BinaryWriter(Stream)
    writer.Write(1)
End Using

備註

您可以使用此方法所傳回的資料流程, 對記憶體對應檔案進行順序存取, 例如, 用於處理序間通訊。You can use the stream returned by this method for sequential access to a memory-mapped file, such as for inter-process communications.

另請參閱

CreateViewStream(Int64, Int64) CreateViewStream(Int64, Int64) CreateViewStream(Int64, Int64) CreateViewStream(Int64, Int64)

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

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

參數

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 stream of memory that has the specified offset and size.

例外狀況

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.

size 大於總虛擬記憶體。size is greater than the total virtual memory.

備註

您可以使用此方法所傳回的資料流程, 對記憶體對應檔案進行順序存取, 例如, 用於處理序間通訊。You can use the stream returned by this method for sequential access to a memory-mapped file, such as for inter-process communications.

若要建立記憶體對應檔案的完整視圖, 請為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.

另請參閱

CreateViewStream(Int64, Int64, MemoryMappedFileAccess) CreateViewStream(Int64, Int64, MemoryMappedFileAccess) CreateViewStream(Int64, Int64, MemoryMappedFileAccess) CreateViewStream(Int64, Int64, MemoryMappedFileAccess)

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

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

參數

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 stream of memory that has the specified characteristics.

例外狀況

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

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

-或--or- access 不是有效的 MemoryMappedFileAccess 列舉值。access is not a valid MemoryMappedFileAccess enumeration value.

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

size 大於總虛擬記憶體。size is greater than the total virtual memory.

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

備註

您可以使用此方法所傳回的資料流程, 對記憶體對應檔案進行順序存取, 例如, 用於處理序間通訊。You can use the stream returned by this method for sequential access to a memory-mapped file, such as for inter-process communications.

若要建立記憶體對應檔案的完整視圖, 請為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. 相關聯的UnmanagedCode列舉:。Associated enumeration: UnmanagedCode.

另請參閱

適用於