简体   繁体   English

飞镖列表最大长度

[英]Dart List Max Length

What is the maximum number of items that a Dart List can store? Dart 列表可以存储的最大项目数是多少? I cant find any resources regarding the maximum length of a list.我找不到有关列表最大长度的任何资源。 Dart API only mentioned growable list, but I am curious about the maximum number of elements a list can hold. Dart API 只提到了可增长列表,但我很好奇一个列表可以容纳的最大元素数。

En, to your question, there's no limitation on how many items can be added to a list but you do have a restriction at hardware device which consumes memory to actually load the list it self.恩,对于您的问题,对于可以添加到列表中的项目数量没有限制,但是您对消耗内存来实际加载列表的硬件设备确实有限制。

That's why there are two main types of lists, with out a builder and the other with builder.这就是为什么有两种主要类型的列表,没有构建器,另一种有构建器。

Using a list with out a builder, will load all elements on the list at once, which is perfect when you know in advance you won't have many, for example top ten articles, a drawer etc..使用没有构建器的列表,将一次加载列表中的所有元素,当您事先知道不会有很多元素时,这是完美的,例如前十篇文章,抽屉等。

Using a list with builder, is basically used to prevent loading (in this lame example) 1000 records at once, rather load them on demand while you start scrolling and dismissing the items in memory when you scroll enough.将列表与构建器一起使用,基本上用于防止一次加载(在这个蹩脚的示例中)1000 条记录,而是在您开始滚动时按需加载它们,并在您滚动到足够大时消除内存中的项目。

Think about this, if you have 10 items it should not be a problem using a normal list, but imagine you have 1000.想想看,如果您有 10 个项目,使用普通列表应该不会有问题,但想象一下您有 1000 个。

First, 1000 won't fit on the screen, each of them will consume a bit of memory leading to battery consumption and stuttering depending on performance.首先,1000 不适合屏幕,他们每个人都会消耗一点内存,导致电池消耗和口吃,具体取决于性能。 That's why when you know in advance you will have lots of items, using a list builder is recommended, flutter will dismiss previous elements of the list and load new ones while scrolling preventing the case I mention of using a normal list.这就是为什么当您事先知道您将有很多项目时,建议使用列表构建器,flutter 会在滚动时忽略列表的先前元素并加载新元素,从而防止出现我提到的使用普通列表的情况。

So, about your question i'm not sure if there is a limit in dart list items count.所以,关于你的问题,我不确定飞镖列表项目数是否有限制。 But, what we should do if there an limit !!但是,如果有限制,我们该怎么办!! in this case we must use if statement the check the list length if it reach the limit then store the data in second list.在这种情况下,我们必须使用 if 语句检查列表长度是否达到限制,然后将数据存储在第二个列表中。 the idea is to split your data in this case to multiple of lists.这个想法是在这种情况下将您的数据拆分为多个列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM