C# Threaded image processing

前端 未结 3 704
自闭症患者
自闭症患者 2020-12-21 07:20
                    for (int x = 0; x < blockCountX; x++)
                    {
                        for (int y = 0; y < blockCountY; y++)
                          


        
3条回答
  •  一个人的身影
    2020-12-21 07:34

    1. I think, encapsulating chunk location among image data in a class is not that bad. I can't see any other option.
    2. As an optimization, you can grab pixel pointer from image.Scan0 if you don't have any restriction about unsafe operations.
    3. Creating a fresh image for each block is not a very clever idea. Pass region of interest to the thread.
    4. If you can use .NET Framework 4, use Parallel.ForEach for such usages. If you can't use it, you can use thread pools. I guess your computer does not have (2048 x 2048) / (256 x 256) = 64 core CPU.
    5. Updating global hex map after a thread termination may improve performance dramatically. Due to Dictionary is not thread-safe, locking global hex map inner loop within a thread is not good idea.

提交回复
热议问题