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

RuntimeHelpers クラス

コンパイラのサポート提供する静的メソッド静的プロパティセット提供します。このクラス継承できません。

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

使用例使用例

PrepareConstrainedRegions メソッド使用してハンドル確実に設定する方法次のコード例示しますハンドル指定した既存ハンドル確実に設定するには、ネイティブ ハンドル割り当てと SafeHandle オブジェクト内でのそのハンドル以降記録分離不可能な状態にすることが必要です。これらの操作間でエラー発生すると (スレッド中止メモリ不足例外によるエラーなど)、ネイティブ ハンドルリークされることになりますPrepareConstrainedRegions メソッド使用すると、ハンドルリーク確実に防ぐことができます

<StructLayout(LayoutKind.Sequential)> _
Structure MyStruct
    Public m_outputHandle As IntPtr
End Structure 'MyStruct


NotInheritable Class MySafeHandle
    Inherits SafeHandle

    ' Called by P/Invoke when returning SafeHandles
    Public Sub New()
        MyBase.New(IntPtr.Zero, True)

    End Sub


    Public Function AllocateHandle() As
 MySafeHandle
        ' Allocate SafeHandle first to avoid failure later.
        Dim sh As New MySafeHandle()

        RuntimeHelpers.PrepareConstrainedRegions()
        Try
        Finally
            Dim myStruct As New
 MyStruct()
            NativeAllocateHandle(myStruct)
            sh.SetHandle(myStruct.m_outputHandle)
        End Try

        Return sh

    End Function


[StructLayout(LayoutKind.Sequential)]
struct MyStruct
{
    public IntPtr m_outputHandle;
}

sealed class MySafeHandle : SafeHandle
{
    // Called by P/Invoke when returning SafeHandles
    public MySafeHandle()
        : base(IntPtr.Zero, true)
    {
    }

    public MySafeHandle AllocateHandle()
    {
        // Allocate SafeHandle first to avoid failure later.
        MySafeHandle sh = new MySafeHandle();

        RuntimeHelpers.PrepareConstrainedRegions();
        try { }
        finally
        {
            MyStruct myStruct = new MyStruct();
            NativeAllocateHandle(ref myStruct);
            sh.SetHandle(myStruct.m_outputHandle);
        }

        return sh;
    }

継承階層継承階層
System.Object
  System.Runtime.CompilerServices.RuntimeHelpers
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
RuntimeHelpers メンバ
System.Runtime.CompilerServices 名前空間


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

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

辞書ショートカット

すべての辞書の索引

「RuntimeHelpers クラス」の関連用語

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

   

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



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

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

©2025 GRAS Group, Inc.RSS