DEBUG and RELEASE modeVersion 1.0.2 added parameter guards that check the length of the allocated Memory/IMemoryOwner which will throw if the length is not _exactly_ width * height:
Guard.IsTrue(pixelMemory.Length == width * height, nameof(pixelMemory), "The length of the input memory doesn't match the specified image size");
This prevents passing a Memory/IMemoryOwner allocated larger than needed. For example, I can no longer use memory from a MemoryPool
Thinking the guard should be >= instead. I'd be happy to submit a PR.
var memowner = MemoryPool<L8>.Shared.Rent(wid * ht);
var image = ISImage.WrapMemory(memowner, wid, ht); // <- throws if pool block is larger than width * height
Windows 10, Azure pipelines (unit tests)
Makes sense to me. @JimBobSquarePants @Sergio0694 thoughts?
Yeah seems ok to me also.
A bit of a weird scenario, but I can understand how this would make sense, sure. I'd have been against this given that callers could just pre-slice the input Memory<T> to the right length, but since that's not doable for IMemoryOwner<T> I guess keeping a consistent behavior between the various overloads makes sense. This is conceptually the same behavior the void* overload has too, if that matters. So yeah, I'd say this seems ok to me as well 馃檪
@Sergio0694 very accurate analysis thanks!
@jeffska looks like we have consensus feel free to PR the change.
Most helpful comment
A bit of a weird scenario, but I can understand how this would make sense, sure. I'd have been against this given that callers could just pre-slice the input
Memory<T>to the right length, but since that's not doable forIMemoryOwner<T>I guess keeping a consistent behavior between the various overloads makes sense. This is conceptually the same behavior thevoid*overload has too, if that matters. So yeah, I'd say this seems ok to me as well 馃檪