UnmanagedMemoryStream.Write 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
오버로드
| Name | Description |
|---|---|
| Write(ReadOnlySpan<Byte>) |
제공된 바이트 범위의 데이터를 사용하여 현재 관리되지 않는 메모리 스트림에 바이트 블록을 씁니다. |
| Write(Byte[], Int32, Int32) |
버퍼의 데이터를 사용하여 현재 스트림에 바이트 블록을 씁니다. |
Write(ReadOnlySpan<Byte>)
- Source:
- UnmanagedMemoryStream.cs
- Source:
- UnmanagedMemoryStream.cs
- Source:
- UnmanagedMemoryStream.cs
- Source:
- UnmanagedMemoryStream.cs
- Source:
- UnmanagedMemoryStream.cs
제공된 바이트 범위의 데이터를 사용하여 현재 관리되지 않는 메모리 스트림에 바이트 블록을 씁니다.
public:
override void Write(ReadOnlySpan<System::Byte> buffer);
public:
override void Write(ReadOnlySpan<System::Byte> source);
public override void Write(ReadOnlySpan<byte> buffer);
public override void Write(ReadOnlySpan<byte> source);
override this.Write : ReadOnlySpan<byte> -> unit
override this.Write : ReadOnlySpan<byte> -> unit
Public Overrides Sub Write (buffer As ReadOnlySpan(Of Byte))
Public Overrides Sub Write (source As ReadOnlySpan(Of Byte))
매개 변수
- sourcebuffer
- ReadOnlySpan<Byte>
현재 관리되지 않는 메모리 스트림에 바이트를 복사할 바이트의 범위입니다.
적용 대상
Write(Byte[], Int32, Int32)
- Source:
- UnmanagedMemoryStream.cs
- Source:
- UnmanagedMemoryStream.cs
- Source:
- UnmanagedMemoryStream.cs
- Source:
- UnmanagedMemoryStream.cs
- Source:
- UnmanagedMemoryStream.cs
버퍼의 데이터를 사용하여 현재 스트림에 바이트 블록을 씁니다.
public:
override void Write(cli::array <System::Byte> ^ buffer, int offset, int count);
public override void Write(byte[] buffer, int offset, int count);
override this.Write : byte[] * int * int -> unit
Public Overrides Sub Write (buffer As Byte(), offset As Integer, count As Integer)
매개 변수
- buffer
- Byte[]
바이트를 현재 스트림에 복사할 바이트 배열입니다.
- offset
- Int32
현재 스트림에 바이트 복사를 시작할 버퍼의 오프셋입니다.
- count
- Int32
현재 스트림에 쓸 바이트 수입니다.
예외
스트림이 닫혔습니다.
기본 메모리는 쓰기를 지원하지 않습니다.
-또는-
스트림에 쓰려고 시도하고 속성이 CanWrite .입니다 false.
-또는-
count 값이 스트림의 용량보다 큰 경우
-또는-
위치는 스트림 용량의 끝에 있습니다.
I/O 오류가 발생합니다.
지정된 매개 변수 중 하나가 0보다 작습니다.
offset 매개 변수에서 매개 변수의 길이를 buffer 뺀 값이 매개 변수보다 작습니다count.
매개 변수는 buffer .입니다 null.
예제
다음 코드 예제에서는 클래스를 사용하여 UnmanagedMemoryStream 관리되지 않는 메모리에서 읽고 쓰는 방법을 보여 줍니다. 관리되지 않는 메모리 블록은 클래스를 사용하여 Marshal 할당 및 할당 취소됩니다.
// Note: you must compile this sample using the unsafe flag.
// From the command line, type the following: csc sample.cs /unsafe
using System;
using System.IO;
using System.Text;
using System.Runtime.InteropServices;
unsafe class TestWriter
{
static void Main()
{
// Create some data to read and write.
byte[] message = UnicodeEncoding.Unicode.GetBytes("Here is some data.");
// Allocate a block of unmanaged memory and return an IntPtr object.
IntPtr memIntPtr = Marshal.AllocHGlobal(message.Length);
// Get a byte pointer from the IntPtr object.
byte* memBytePtr = (byte*)memIntPtr.ToPointer();
// Create an UnmanagedMemoryStream object using a pointer to unmanaged memory.
UnmanagedMemoryStream writeStream = new UnmanagedMemoryStream(memBytePtr, message.Length, message.Length, FileAccess.Write);
// Write the data.
writeStream.Write(message, 0, message.Length);
// Close the stream.
writeStream.Close();
// Create another UnmanagedMemoryStream object using a pointer to unmanaged memory.
UnmanagedMemoryStream readStream = new UnmanagedMemoryStream(memBytePtr, message.Length, message.Length, FileAccess.Read);
// Create a byte array to hold data from unmanaged memory.
byte[] outMessage = new byte[message.Length];
// Read from unmanaged memory to the byte array.
readStream.Read(outMessage, 0, message.Length);
// Close the stream.
readStream.Close();
// Display the data to the console.
Console.WriteLine(UnicodeEncoding.Unicode.GetString(outMessage));
// Free the block of unmanaged memory.
Marshal.FreeHGlobal(memIntPtr);
Console.ReadLine();
}
}
설명
쓰기는 스트림의 현재 위치에서 발생합니다.