Browse Source

maxPoolSizeInBytes parameter + safer indexer for Buffer<T>

af/merge-core
Anton Firszov 8 years ago
parent
commit
b63dbd3a6d
  1. 15
      src/ImageSharp/Memory/ArrayPoolMemoryManager.cs
  2. 4
      src/ImageSharp/Memory/Buffer{T}.cs

15
src/ImageSharp/Memory/ArrayPoolMemoryManager.cs

@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.Memory
{ {
/// <summary> /// <summary>
/// Defines the default maximum size of pooled arrays. /// Defines the default maximum size of pooled arrays.
/// Currently set to a value equivalent to 16 Megapixels of an <see cref="Rgba32"/> image. /// Currently set to a value equivalent to 16 MegaPixels of an <see cref="Rgba32"/> image.
/// </summary> /// </summary>
public const int DefaultMaxSizeInBytes = 4096 * 4096 * 4; public const int DefaultMaxSizeInBytes = 4096 * 4096 * 4;
@ -22,8 +22,19 @@ namespace SixLabors.ImageSharp.Memory
/// Initializes a new instance of the <see cref="ArrayPoolMemoryManager"/> class. /// Initializes a new instance of the <see cref="ArrayPoolMemoryManager"/> class.
/// </summary> /// </summary>
public ArrayPoolMemoryManager() public ArrayPoolMemoryManager()
: this(DefaultMaxSizeInBytes)
{ {
this.pool = ArrayPool<byte>.Create(DefaultMaxSizeInBytes, 50); }
/// <summary>
/// Initializes a new instance of the <see cref="ArrayPoolMemoryManager"/> class.
/// <param name="maxPoolSizeInBytes">The maximum size of pooled arrays. Arrays over the thershold are gonna be always allocated.</param>
/// </summary>
public ArrayPoolMemoryManager(int maxPoolSizeInBytes)
{
Guard.MustBeGreaterThan(maxPoolSizeInBytes, 0, nameof(maxPoolSizeInBytes));
this.pool = ArrayPool<byte>.Create(maxPoolSizeInBytes, 50);
} }
/// <inheritdoc /> /// <inheritdoc />

4
src/ImageSharp/Memory/Buffer{T}.cs

@ -99,7 +99,9 @@ namespace SixLabors.ImageSharp.Memory
get get
{ {
DebugGuard.MustBeLessThan(index, this.Length, nameof(index)); DebugGuard.MustBeLessThan(index, this.Length, nameof(index));
return ref this.Array[index];
Span<T> span = this.Span;
return ref span[index];
} }
} }

Loading…
Cancel
Save