/// <summary> /// Rent 'n' buffers -> return all -> re-rent, verify if there is at least one in common. /// </summary> private bool CheckIsPooled <T>(int n, int count) where T : struct { lock (this.monitor) { T[][] original = new T[n][]; for (int i = 0; i < n; i++) { original[i] = PixelDataPool <T> .Rent(count); } for (int i = 0; i < n; i++) { PixelDataPool <T> .Return(original[i]); } T[][] verification = new T[n][]; for (int i = 0; i < n; i++) { verification[i] = PixelDataPool <T> .Rent(count); } return(original.Intersect(verification).Any()); } }
public void PixelDataPoolDoesNotThrowWhenReturningNonPooled() { Color[] pixels = new Color[1024]; PixelDataPool <Color> .Return(pixels); Assert.True(pixels.Length >= 1024); }
public void PixelDataPoolDoesNotThrowWhenReturningNonPooled() { Rgba32[] pixels = new Rgba32[1024]; PixelDataPool <Rgba32> .Return(pixels); Assert.True(pixels.Length >= 1024); }
public void PixelDataPoolCleansRentedArray() { Color[] pixels = PixelDataPool <Color> .Rent(256); for (int i = 0; i < pixels.Length; i++) { pixels[i] = Color.Azure; } Assert.True(pixels.All(p => p == Color.Azure)); PixelDataPool <Color> .Return(pixels); Assert.True(pixels.All(p => p == default(Color))); }
public void PixelDataPoolRentsEmptyArray() { for (int i = 16; i < 1024; i += 16) { Color[] pixels = PixelDataPool <Color> .Rent(i); Assert.True(pixels.All(p => p == default(Color))); PixelDataPool <Color> .Return(pixels); } for (int i = 16; i < 1024; i += 16) { Color[] pixels = PixelDataPool <Color> .Rent(i); Assert.True(pixels.All(p => p == default(Color))); PixelDataPool <Color> .Return(pixels); } }