使用Marshal.AllocHGlobal时GC.AddMemoryPressure合适吗?
Is GC.AddMemoryPressure appropriate when using Marshal.AllocHGlobal?
有
IntPtr ip = Marshal.AllocHGlobal(size);
隐式增加内存压力(a la GC.AddMemoryPressure)?没错,它正在分配非托管内存,但它并没有这样做 "out of the sight of CLR." 我可以看到关于添加或不添加的参数。
似乎可以(也许应该)。但我需要知道它实际上 做了什么。
根据 source code (or for .NET Core),不,它不会调用 GC.AddMemoryPressure
。
有
IntPtr ip = Marshal.AllocHGlobal(size);
隐式增加内存压力(a la GC.AddMemoryPressure)?没错,它正在分配非托管内存,但它并没有这样做 "out of the sight of CLR." 我可以看到关于添加或不添加的参数。
似乎可以(也许应该)。但我需要知道它实际上 做了什么。
根据 source code (or for .NET Core),不,它不会调用 GC.AddMemoryPressure
。