Tag: 不安全指针

不安全的指针迭代和位图 – 为什么UInt64更快?

我一直在做一些不安全的位图操作,并发现增加指针的次数可以带来一些重大的性能提升。 我不知道为什么会这样,即使你在循环中做了更多的按位操作,对指针进行更少的迭代仍然会更好。 因此,例如,使用UInt64迭代超过32位像素,而不是使用UInt64迭代两个像素,并在一个周期内执行两次操作。 以下是通过读取两个像素并对其进行修改(当然,它会因奇数宽度的图像而失败,但仅用于测试)。 private void removeBlueWithTwoPixelIteration() { // think of a big image with data Bitmap bmp = new Bitmap(15000, 15000, System.Drawing.Imaging.PixelFormat.Format32bppArgb); TimeSpan startTime, endTime; unsafe { UInt64 doublePixel; UInt32 pixel1; UInt32 pixel2; const int readSize = sizeof(UInt64); const UInt64 rightHalf = UInt32.MaxValue; PerformanceCounter pf = new PerformanceCounter(“System”, “System Up Time”); pf.NextValue(); BitmapData bd […]