列表与词典(最大尺寸,元素的数量) [英] List vs. Dictionary (Maximum Size, Number of Elements)

查看:190
本文介绍了列表与词典(最大尺寸,元素的数量)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图确定一个列表和字典的最大尺寸(在RAM)。我也很好奇,元素/项的每个可以容纳和每个条目的内存占用的最大数量。

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 memory footprint per entry.

我的理由很简单:我最喜欢的程序员,我有点懒(这是一种美德)。当我写一个程序,我想一旦写出来,并尽量面向未来它尽可能多地。我目前正在写一个使用列表程序,但注意到,迭代器想要一个整数。因为我的程序的功能仅受可用内存/编码风格,我喜欢写,所以我可以使用带有Int64s或可能BigInts列表(用迭代器)。我见过的IEnumerable这里可能,但想看看如果我可以的东西,而不是改写一切一的Int64到Dictionary对象作为重点。如果可以,我想知道的是,成本可能会比改写。

My reasons are simple: I, like most programmers, am somewhat lazy (this is a virtue). When I write a program, I like to write it once, and try to future-proof it as much as possible. I am currently writing a program that uses Lists, but noticed that the iterator wants an integer. Since the capabilities of my program are only limited by available memory / coding style, I'd like to write it so I can use a List with Int64s or possibly BigInts (as the iterators). I've seen IEnumerable as a possibility here, but would like to find out if I can just stuff a Int64 into a Dictionary object as the key, instead of rewriting everything. If I can, I'd like to know what the cost of that might be compared to rewriting it.

我的希望是要我的程序证明是有用的,我只需要重新编译打5年的时间采取增加内存的优势。

My hope is that should my program prove useful, I need only hit recompile in 5 years time to take advantage of the increase in memory.

推荐答案

时,它的类文件中规定?没有,那么它是不确定的。

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

在当前实现方面,有在RAM中没有最大规模的类本身,如果你创建一个值类型是2MB的大小,推几千元到一个列表,并收到一个内存溢出异常,这是没什么做名单,其中,T>

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<T>.

在内部,名单,其中,T&GT; 取值运作将prevent它曾经有超过20亿的项目。这是很难来一个快速的答案与词典&LT; TKEY的,TValue&GT; ,因为事物的方式定位在更复杂,但说真的,如果我一直在寻找应对一个十亿项目(如果一个32位的值,例如,那么4GB),我会寻找将它们存储在数据库中,并使用数据访问code找回它们。

Internally, List<T>s workings would prevent it from ever having more than 2billion items. It's harder to come to a quick answer with Dictionary<TKey, TValue>, 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.

最起码,一旦你处理一个单一的数据结构,这是4GB的大小,滚动自己的自定义集合类不再像以前那样另起炉灶计数。

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.

这篇关于列表与词典(最大尺寸,元素的数量)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆