Generics vs. Array Lists

后端 未结 12 1542
孤独总比滥情好
孤独总比滥情好 2020-12-10 12:19

The system I work on here was written before .net 2.0 and didn\'t have the benefit of generics. It was eventually updated to 2.0, but none of the code was refactored due to

12条回答
  •  半阙折子戏
    2020-12-10 12:46

    Generics has much better performance especially if you'll be using value-type (int, bool, struct etc.) where you'll gain a noticeble performance gain.

    1. Using Arraylist with value-types causes boxing/unboxing which if done several hundred times is substantialy slower then using generic List.

    2. when storing value-types as object you'll up to four time memory per item. While this amount won't drain your RAM the cache memory that is smaller could contain less items, Which means that while iterating a long collections there would be many copies from the main memory to the cache that would slow your application.

    I wrote about here.

提交回复
热议问题