dotnet/runtime

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

開放

#54,297 建立於 2021年6月16日

 (6 則留言) (1 個反應) (0 位負責人)C# (5,445 個分叉)batch import
area-Interop-coreclrhelp wanted

倉庫指標

星標
 (17,886 顆星)
PR 合併指標
 (平均合併 12天 11小時) (30 天內合併 661 個 PR)

描述

#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.

貢獻者指南