Browse Source

- Optional param -> second method

pull/431/head
Lauri Kotilainen 8 years ago
parent
commit
cf13ebfe19
  1. 8
      src/ImageSharp/Memory/ArrayPoolMemoryManager.cs
  2. 13
      src/ImageSharp/Memory/MemoryManager.cs
  3. 8
      src/ImageSharp/Memory/NullMemoryManager.cs

8
src/ImageSharp/Memory/ArrayPoolMemoryManager.cs

@ -30,7 +30,13 @@ namespace SixLabors.ImageSharp.Memory
}
/// <inheritdoc />
internal override Buffer<T> Allocate<T>(int itemCount, bool clear = false)
internal override Buffer<T> Allocate<T>(int itemCount)
{
return this.Allocate<T>(itemCount, false);
}
/// <inheritdoc />
internal override Buffer<T> Allocate<T>(int itemCount, bool clear)
{
int itemSizeBytes = Unsafe.SizeOf<T>();
int bufferSizeInBytes = itemCount * itemSizeBytes;

13
src/ImageSharp/Memory/MemoryManager.cs

@ -11,6 +11,17 @@ namespace SixLabors.ImageSharp.Memory
/// </summary>
public abstract class MemoryManager
{
/// <summary>
/// Allocates a <see cref="Buffer{T}"/> of size <paramref name="size"/>.
/// Note: Depending on the implementation, the buffer may not cleared before
/// returning, so it may contain data from an earlier use.
/// </summary>
/// <typeparam name="T">Type of the data stored in the buffer</typeparam>
/// <param name="size">Size of the buffer to allocate</param>
/// <returns>A buffer of values of type <typeparamref name="T"/>.</returns>
internal abstract Buffer<T> Allocate<T>(int size)
where T : struct;
/// <summary>
/// Allocates a <see cref="Buffer{T}"/> of size <paramref name="size"/>, optionally
/// clearing the buffer before it gets returned.
@ -19,7 +30,7 @@ namespace SixLabors.ImageSharp.Memory
/// <param name="size">Size of the buffer to allocate</param>
/// <param name="clear">True to clear the backing memory of the buffer</param>
/// <returns>A buffer of values of type <typeparamref name="T"/>.</returns>
internal abstract Buffer<T> Allocate<T>(int size, bool clear = false)
internal abstract Buffer<T> Allocate<T>(int size, bool clear)
where T : struct;
/// <summary>

8
src/ImageSharp/Memory/NullMemoryManager.cs

@ -6,7 +6,13 @@
public class NullMemoryManager : MemoryManager
{
/// <inheritdoc />
internal override Buffer<T> Allocate<T>(int size, bool clear = false)
internal override Buffer<T> Allocate<T>(int size)
{
return new Buffer<T>(new T[size], size);
}
/// <inheritdoc />
internal override Buffer<T> Allocate<T>(int size, bool clear)
{
return new Buffer<T>(new T[size], size);
}

Loading…
Cancel
Save