You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have verified that I am running the latest version of ImageSharp
I have verified if the problem exist in both DEBUG and RELEASE mode
I have searched open and closed issues to ensure it has not already been reported
Description
When trying to process images, I want to pin the underlying Memory to have access to the pointer and run some SIMD operations. However, when that Memory was allocated with either one of the provided MemoryAllocator classes, I can pin it 1 time only, and on the second try I get IntPtr.Zero as the Pointer.
Steps to Reproduce
The first 2 examples are using ArrayPoolMemoryAllocator and SimpleGcMemoryAllocator and they both fail:
[Test]publicunsafevoidMemoryPinningTest_ArrayPoolMemoryAllocator(){varallocator=newSixLabors.ImageSharp.Memory.ArrayPoolMemoryAllocator();usingvarmemory=allocator.Allocate<L8>(100);// SixLabors.ImageSharp.Memory.ArrayPoolMemoryAllocator.Buffer<SixLabors.ImageSharp.PixelFormats.L8>using(varpin=memory.Memory.Pin()){Assert.AreNotEqual(IntPtr.Zero,(IntPtr)pin.Pointer);}using(varpin=memory.Memory.Pin()){Assert.AreNotEqual(IntPtr.Zero,(IntPtr)pin.Pointer);// this line fails}}[Test]publicunsafevoidMemoryPinningTest_SimpleGcMemoryAllocator(){varallocator=newSixLabors.ImageSharp.Memory.SimpleGcMemoryAllocator();usingvarmemory=allocator.Allocate<L8>(100);// SixLabors.ImageSharp.Memory.Internals.BasicArrayBuffer<SixLabors.ImageSharp.PixelFormats.L8>using(varpin=memory.Memory.Pin()){Assert.AreNotEqual(IntPtr.Zero,(IntPtr)pin.Pointer);}using(varpin=memory.Memory.Pin()){Assert.AreNotEqual(IntPtr.Zero,(IntPtr)pin.Pointer);// this line fails}}
These other examples are using standard .NET ways to allocate and pin memory and they succeed:
@Kloizdena thanks a lot for spotting this! I filed a fix which you will be able to consume through MyGet once PR is merged, but note that we will replace ArrayPoolMemoryAllocator in our next official NuGet release and do a bunch of other necessary breaking changes around low-level pixel manipulation. See #1739.
Prerequisites
DEBUG
andRELEASE
modeDescription
When trying to process images, I want to pin the underlying Memory to have access to the pointer and run some SIMD operations. However, when that Memory was allocated with either one of the provided MemoryAllocator classes, I can pin it 1 time only, and on the second try I get IntPtr.Zero as the Pointer.
Steps to Reproduce
The first 2 examples are using ArrayPoolMemoryAllocator and SimpleGcMemoryAllocator and they both fail:
These other examples are using standard .NET ways to allocate and pin memory and they succeed:
System Configuration
The text was updated successfully, but these errors were encountered: