diff --git a/src/ImageSharp/Configuration.cs b/src/ImageSharp/Configuration.cs
index 37db84627f..bd6c11235f 100644
--- a/src/ImageSharp/Configuration.cs
+++ b/src/ImageSharp/Configuration.cs
@@ -86,7 +86,7 @@ namespace SixLabors.ImageSharp
///
/// Gets or sets the that is currently in use.
///
- public MemoryManager MemoryManager { get; set; } = new ArrayPoolMemoryManager(512);
+ public MemoryManager MemoryManager { get; set; } = new ArrayPoolMemoryManager();
///
/// Gets the maximum header size of all the formats.
diff --git a/src/ImageSharp/Memory/ArrayPoolMemoryManager.cs b/src/ImageSharp/Memory/ArrayPoolMemoryManager.cs
index f77a1f8ac1..9df9e794aa 100644
--- a/src/ImageSharp/Memory/ArrayPoolMemoryManager.cs
+++ b/src/ImageSharp/Memory/ArrayPoolMemoryManager.cs
@@ -10,23 +10,20 @@ namespace SixLabors.ImageSharp.Memory
///
public class ArrayPoolMemoryManager : MemoryManager
{
- private readonly int minSizeBytes;
+ ///
+ /// Defines the default maximum size of pooled arrays.
+ /// Currently set to a value equivalent to 16 Megapixels of an image.
+ ///
+ public const int DefaultMaxSizeInBytes = 4096 * 4096 * 4;
+
private readonly ArrayPool pool;
///
/// Initializes a new instance of the class.
- /// By passing an integer greater than 0 as , a
- /// minimum threshold for pooled allocations is set. Any allocation requests that
- /// would require less size than the threshold will not be managed within the array pool.
///
- ///
- /// Minimum size, in bytes, before an array pool is used to satisfy the request.
- ///
- public ArrayPoolMemoryManager(int minSizeBytes = 0)
+ public ArrayPoolMemoryManager()
{
- this.minSizeBytes = minSizeBytes;
-
- this.pool = ArrayPool.Create(CalculateMaxArrayLength(), 50);
+ this.pool = ArrayPool.Create(DefaultMaxSizeInBytes, 50);
}
///
@@ -41,14 +38,6 @@ namespace SixLabors.ImageSharp.Memory
int itemSizeBytes = Unsafe.SizeOf();
int bufferSizeInBytes = itemCount * itemSizeBytes;
- if (this.minSizeBytes > 0 && bufferSizeInBytes < this.minSizeBytes)
- {
- // Minimum size set to 8 bytes to get past a misbehaving test
- // (otherwise PngDecoderTests.Decode_IncorrectCRCForNonCriticalChunk_ExceptionIsThrown fails for the wrong reason)
- // TODO: Remove this once the test is fixed
- return new Buffer(new T[Math.Max(itemCount, 8)], itemCount);
- }
-
byte[] byteBuffer = this.pool.Rent(bufferSizeInBytes);
var buffer = new Buffer(Unsafe.As(byteBuffer), itemCount, this);
if (clear)
@@ -62,19 +51,8 @@ namespace SixLabors.ImageSharp.Memory
///
internal override void Release(Buffer buffer)
{
- var byteBuffer = Unsafe.As(buffer.Array);
+ byte[] byteBuffer = Unsafe.As(buffer.Array);
this.pool.Return(byteBuffer);
}
-
- ///
- /// Heuristically calculates a reasonable maxArrayLength value for the backing .
- ///
- /// The maxArrayLength value
- internal static int CalculateMaxArrayLength()
- {
- const int MaximumExpectedImageSize = 16384 * 16384;
- const int MaximumBytesPerPixel = 4;
- return MaximumExpectedImageSize * MaximumBytesPerPixel;
- }
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/Memory/MemoryManager.cs b/src/ImageSharp/Memory/MemoryManager.cs
index 1cefccfb20..df1ecbd845 100644
--- a/src/ImageSharp/Memory/MemoryManager.cs
+++ b/src/ImageSharp/Memory/MemoryManager.cs
@@ -45,7 +45,7 @@ namespace SixLabors.ImageSharp.Memory
internal Buffer2D Allocate2D(int width, int height, bool clear = false)
where T : struct
{
- var buffer = this.Allocate(width * height, clear);
+ Buffer buffer = this.Allocate(width * height, clear);
return new Buffer2D(buffer, width, height);
}
diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
index d529bbaeb6..e310e1efaf 100644
--- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
+++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
@@ -118,8 +118,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
}
public const string DecodeBaselineJpegOutputName = "DecodeBaselineJpeg";
-
-
+
[Theory]
[WithFile(TestImages.Jpeg.Baseline.Calliphora, CommonNonDefaultPixelTypes, false)]
[WithFile(TestImages.Jpeg.Baseline.Calliphora, CommonNonDefaultPixelTypes, true)]
diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs
index 4cd7ebeea3..41711240c9 100644
--- a/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs
@@ -362,8 +362,9 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
if (typeof(TDest) == typeof(Vector4))
{
- Vector4[] expected = this.ExpectedDestBuffer.Array as Vector4[];
- Vector4[] actual = this.ActualDestBuffer.Array as Vector4[];
+
+ Span expected = this.ExpectedDestBuffer.Span.NonPortableCast();
+ Span actual = this.ActualDestBuffer.Span.NonPortableCast();
for (int i = 0; i < count; i++)
{