List vs. Dictionary (Maximum Size, Number of Elements)

后端 未结 3 448
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-14 11:09

I am attempting to ascertain the maximum sizes (in RAM) of a List and a Dictionary. I am also curious as to the maximum number of elements / entries each can hold, and their

3条回答
  •  时光说笑
    2021-01-14 11:28

    Is it specified in the documentation for the class? No, then it's unspecified.

    In terms of current implementations, there's no maximum size in RAM in the classes themselves, if you create a value type that's 2MB in size, push a few thousand into a list, and receive an out of memory exception, that's nothing to do with List.

    Internally, Lists workings would prevent it from ever having more than 2billion items. It's harder to come to a quick answer with Dictionary, since the way things are positioned within it is more complicated, but really, if I was looking at dealing with a billion items (if a 32-bit value, for example, then 4GB), I'd be looking to store them in a database and retrieve them using data-access code.

    At the very least, once you're dealing with a single data structure that's 4GB in size, rolling your own custom collection class no longer counts as reinventing the wheel.

提交回复
热议问题