Generics memory management

后端 未结 7 774
慢半拍i
慢半拍i 2021-01-05 02:41

I have question regarding how memory is managed for strong type Generics

List ints1 = new List();
ints1.Add(1); ints1.Add(2); ints1.Add         


        
7条回答
  •  盖世英雄少女心
    2021-01-05 03:14

    Question 1: http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx says:

    The List class is the generic equivalent of the ArrayList class. It implements the IList generic interface using an array whose size is dynamically increased as required.

    This looks like a simple array, that is just reallocated if it overflows. AFAIKR the size is doubled on every reallocation - I researched that once, but can't remember what for.

    The array is allocated on the managed heap, just as it would if you just declared it.

提交回复
热议问题