dotnet/runtime

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

Open

#54 297 ouverte le 16 juin 2021

Voir sur GitHub
 (6 commentaires) (1 réaction) (0 assignés)C# (5 445 forks)batch import
area-Interop-coreclrhelp wanted

Métriques du dépôt

Stars
 (17 886 stars)
Métriques de merge PR
 (Merge moyen 12j 11h) (661 PRs mergées en 30 j)

Description

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

Guide contributeur