dotnet/runtime

Audit usages of Marshal.AllocHGlobal for ones that can be replaced with NativeMemory.Alloc

オープン

#54,297 opened on 2021/06/16

 (6 件のコメント) (1 件のリアクション) (0 人の担当者)C# (5,445 件のフォーク)batch import
area-Interop-coreclrhelp wanted

Repository metrics

Stars
 (17,886 個のスター)
PR merge metrics
 (平均マージ 12d 11h) (30d で 661 merged PRs)

説明

#54006 introduced new NativeMemory APIs that wrap malloc, calloc, realloc, and aligned_alloc. We should audit existing usages of Marshal.AllocHGlobal for cases where it can be safely replaced with malloc.

Notably cases like StringToPtrHGlobal do not qualify as they are documented to be a call to LocalAlloc on Windows. However, on Unix and in cases where this is not a definitive contract, it should be safe to replace these calls with faster ones to NativeMemory.

コントリビューターガイド