C# Dictionary Performance

前端 未结 5 1702
死守一世寂寞
死守一世寂寞 2021-01-05 20:01

I am using a Dictionary to store data, and will be caching it. I would like to avoid server memory issues, and have good performance by limiting the size of the Dictionary&

5条回答
  •  醉话见心
    2021-01-05 20:45

    One thing to keep in mind is that when you initialize a Dictionary you can set the initial capacity. If you know how big your list will be, set it to the correct size and you won't have any "wasted" space. If you don't specify the capacity, it will set a default starting capacity and resize/grow as needed, which takes a performance hit.

提交回复
热议问题