Browse Source

cleanup & comments

pull/1730/head
Anton Firszov 5 years ago
parent
commit
4865adab73
  1. 2
      src/ImageSharp/Memory/Allocators/Internals/UniformUnmanagedMemoryPool.cs
  2. 2
      src/ImageSharp/Memory/Allocators/UniformUnmanagedMemoryPoolMemoryAllocator.cs
  3. 9
      src/ImageSharp/Memory/Allocators/UnmanagedMemoryAllocator.cs
  4. 8
      src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.Consumed.cs
  5. 8
      src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.Owned.cs
  6. 8
      src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.cs
  7. 2
      tests/ImageSharp.Tests/Image/LargeImageIntegrationTests.cs

2
src/ImageSharp/Memory/Allocators/Internals/UniformUnmanagedMemoryPool.cs

@ -10,7 +10,7 @@ namespace SixLabors.ImageSharp.Memory.Internals
{ {
internal partial class UniformUnmanagedMemoryPool internal partial class UniformUnmanagedMemoryPool
#if !NETSTANDARD1_3 #if !NETSTANDARD1_3
// In case UniformUnmanagedMemoryPool is finalized, we prefer to run it's finalizer after the guard finalizers, // In case UniformUnmanagedMemoryPool is finalized, we prefer to run its finalizer after the guard finalizers,
// but we should not rely on this. // but we should not rely on this.
: System.Runtime.ConstrainedExecution.CriticalFinalizerObject : System.Runtime.ConstrainedExecution.CriticalFinalizerObject
#endif #endif

2
src/ImageSharp/Memory/Allocators/UniformUnmanagedMemoryPoolMemoryAllocator.cs

@ -147,7 +147,7 @@ namespace SixLabors.ImageSharp.Memory
private static long GetDefaultMaxPoolSizeBytes() private static long GetDefaultMaxPoolSizeBytes()
{ {
#if NETCORE31COMPATIBLE #if NETCORE31COMPATIBLE
// On .NET Core 3.1+, determine the pool as portion of the total available memory. // On 64 bit .NET Core 3.1+, set the pool size to a portion of the total available memory.
// There is a bug in GC.GetGCMemoryInfo() on .NET 5 + 32 bit, making TotalAvailableMemoryBytes unreliable: // There is a bug in GC.GetGCMemoryInfo() on .NET 5 + 32 bit, making TotalAvailableMemoryBytes unreliable:
// https://github.com/dotnet/runtime/issues/55126#issuecomment-876779327 // https://github.com/dotnet/runtime/issues/55126#issuecomment-876779327
if (Environment.Is64BitProcess || !RuntimeInformation.FrameworkDescription.StartsWith(".NET 5.0")) if (Environment.Is64BitProcess || !RuntimeInformation.FrameworkDescription.StartsWith(".NET 5.0"))

9
src/ImageSharp/Memory/Allocators/UnmanagedMemoryAllocator.cs

@ -7,14 +7,15 @@ using SixLabors.ImageSharp.Memory.Internals;
namespace SixLabors.ImageSharp.Memory namespace SixLabors.ImageSharp.Memory
{ {
/// <summary>
/// A <see cref="MemoryAllocator"/> implementation that allocates memory on the unmanaged heap
/// without any pooling.
/// </summary>
internal class UnmanagedMemoryAllocator : MemoryAllocator internal class UnmanagedMemoryAllocator : MemoryAllocator
{ {
private readonly int bufferCapacityInBytes; private readonly int bufferCapacityInBytes;
public UnmanagedMemoryAllocator(int bufferCapacityInBytes) public UnmanagedMemoryAllocator(int bufferCapacityInBytes) => this.bufferCapacityInBytes = bufferCapacityInBytes;
{
this.bufferCapacityInBytes = bufferCapacityInBytes;
}
protected internal override int GetBufferCapacityInBytes() => this.bufferCapacityInBytes; protected internal override int GetBufferCapacityInBytes() => this.bufferCapacityInBytes;

8
src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.Consumed.cs

@ -50,13 +50,7 @@ namespace SixLabors.ImageSharp.Memory
return ((IList<Memory<T>>)this.source).GetEnumerator(); return ((IList<Memory<T>>)this.source).GetEnumerator();
} }
protected override void Dispose(bool disposing) public override void Dispose() => this.View.Invalidate();
{
if (disposing)
{
this.View.Invalidate();
}
}
} }
} }
} }

8
src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.Owned.cs

@ -129,9 +129,9 @@ namespace SixLabors.ImageSharp.Memory
return this.memoryOwners.Select(mo => mo.Memory).GetEnumerator(); return this.memoryOwners.Select(mo => mo.Memory).GetEnumerator();
} }
protected override void Dispose(bool disposing) public override void Dispose()
{ {
if (this.IsDisposed || !disposing) if (this.IsDisposed)
{ {
return; return;
} }
@ -193,7 +193,9 @@ namespace SixLabors.ImageSharp.Memory
b.View = new MemoryGroupView<T>(b); b.View = new MemoryGroupView<T>(b);
} }
// No-ownership // When the MemoryGroup points to multiple buffers via `groupLifetimeGuard`,
// the lifetime of the individual buffers is managed by the guard.
// Group buffer IMemoryOwner<T>-s d not manage ownership.
private sealed class ObservedBuffer : MemoryManager<T> private sealed class ObservedBuffer : MemoryManager<T>
{ {
private readonly UnmanagedMemoryHandle handle; private readonly UnmanagedMemoryHandle handle;

8
src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.cs

@ -45,13 +45,7 @@ namespace SixLabors.ImageSharp.Memory
public abstract Memory<T> this[int index] { get; } public abstract Memory<T> this[int index] { get; }
/// <inheritdoc /> /// <inheritdoc />
public void Dispose() public abstract void Dispose();
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
protected abstract void Dispose(bool disposing);
/// <inheritdoc /> /// <inheritdoc />
public abstract MemoryGroupEnumerator<T> GetEnumerator(); public abstract MemoryGroupEnumerator<T> GetEnumerator();

2
tests/ImageSharp.Tests/Image/LargeImageIntegrationTests.cs

@ -22,7 +22,7 @@ namespace SixLabors.ImageSharp.Tests
} }
[Fact] [Fact]
public void PreferContiguousImageBuffers_CreateImage_MaximumPoolSizeMegabytes() public void PreferContiguousImageBuffers_CreateImage_BufferIsContiguous()
{ {
// Run remotely to avoid large allocation in the test process: // Run remotely to avoid large allocation in the test process:
RemoteExecutor.Invoke(RunTest).Dispose(); RemoteExecutor.Invoke(RunTest).Dispose();

Loading…
Cancel
Save