UnmanagedMemoryStream.Write メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > UnmanagedMemoryStream.Write メソッドの意味・解説 

UnmanagedMemoryStream.Write メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

バッファデータ使用して現在のストリームバイトブロック書き込みます

このメソッドは、CLS準拠していません。  

名前空間: System.IO
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

例外例外
例外種類条件

ObjectDisposedException

ストリーム閉じられました。

NotSupportedException

基になるメモリ書き込みサポートしていません。

または

ストリームへの書き込みが行われようとしましたが、CanWrite プロパティfalse です。

または

count 値がストリーム容量超えてます。

または

位置ストリーム容量末尾です。

IOException

I/O エラー発生しました

ArgumentOutOfRangeException

指定したパラメータいずれかが 0 未満です。

ArgumentException

offset パラメータから buffer パラメータ長さ引いた値が count パラメータ未満です。

ArgumentNullException

buffer パラメータnull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

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 som 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();
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
UnmanagedMemoryStream クラス
UnmanagedMemoryStream メンバ
System.IO 名前空間



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

UnmanagedMemoryStream.Write メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



UnmanagedMemoryStream.Write メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS