UnmanagedMemoryStream クラスとは? わかりやすく解説

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

UnmanagedMemoryStream クラス

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

マネージ コードからメモリのアンマネージ ブロックアクセスできるようにします。

このクラスは、CLS準拠していません。  

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

<CLSCompliantAttribute(False)> _
Public Class UnmanagedMemoryStream
    Inherits Stream
Dim instance As UnmanagedMemoryStream
[CLSCompliantAttribute(false)] 
public class UnmanagedMemoryStream : Stream
[CLSCompliantAttribute(false)] 
public ref class UnmanagedMemoryStream : public
 Stream
/** @attribute CLSCompliantAttribute(false) */ 
public class UnmanagedMemoryStream extends
 Stream
CLSCompliantAttribute(false) 
public class UnmanagedMemoryStream extends
 Stream
解説解説
使用例使用例

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();
    }
}
継承階層継承階層
System.Object
   System.MarshalByRefObject
     System.IO.Stream
      System.IO.UnmanagedMemoryStream
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からUnmanagedMemoryStream クラスを検索した結果を表示しています。
Weblioに収録されているすべての辞書からUnmanagedMemoryStream クラスを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からUnmanagedMemoryStream クラス を検索

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

辞書ショートカット

すべての辞書の索引

「UnmanagedMemoryStream クラス」の関連用語

UnmanagedMemoryStream クラスのお隣キーワード
検索ランキング

   

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



UnmanagedMemoryStream クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS