dotnet/runtime

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

Open

#54,297 创建于 2021年6月16日

在 GitHub 查看
 (6 评论) (1 反应) (0 负责人)C# (5,445 fork)batch import
area-Interop-coreclrhelp wanted

仓库指标

Star
 (17,886 star)
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.

贡献者指南