|
|
|
@ -74,6 +74,10 @@ namespace SixLabors.ImageSharp.Memory |
|
|
|
this.nonPoolAllocator = new UnmanagedMemoryAllocator(unmanagedBufferSizeInBytes); |
|
|
|
} |
|
|
|
|
|
|
|
// This delegate allows overriding the method returning the available system memory,
|
|
|
|
// so we can test our workaround for https://github.com/dotnet/runtime/issues/65466
|
|
|
|
internal static Func<long> GetTotalAvailableMemoryBytes { get; set; } = () => GC.GetGCMemoryInfo().TotalAvailableMemoryBytes; |
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
protected internal override int GetBufferCapacityInBytes() => this.poolBufferSizeInBytes; |
|
|
|
|
|
|
|
@ -152,8 +156,13 @@ namespace SixLabors.ImageSharp.Memory |
|
|
|
// https://github.com/dotnet/runtime/issues/55126#issuecomment-876779327
|
|
|
|
if (Environment.Is64BitProcess || !RuntimeInformation.FrameworkDescription.StartsWith(".NET 5.0")) |
|
|
|
{ |
|
|
|
GCMemoryInfo info = GC.GetGCMemoryInfo(); |
|
|
|
return info.TotalAvailableMemoryBytes / 8; |
|
|
|
long total = GetTotalAvailableMemoryBytes(); |
|
|
|
|
|
|
|
// Workaround for https://github.com/dotnet/runtime/issues/65466
|
|
|
|
if (total > 0) |
|
|
|
{ |
|
|
|
return total / 8; |
|
|
|
} |
|
|
|
} |
|
|
|
#endif
|
|
|
|
|
|
|
|
|