限制领域结果 [英] Limit Realm results

查看:49
本文介绍了限制领域结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何限制Realm返回的对象数量? .findAll返回与查询匹配的所有行,.findFirst仅返回第一行.但是第一个1000呢? .findAll可能返回太多行,从而占用太多内存.

How do I limit the amount of objects Realm returns? .findAll returns all rows matching the query and .findFirst returns only the first. But what about something like first 1000? .findAll may return so many rows that it consumes way too much memory.

推荐答案

最酷的事情是,您无需为Realm担心.从查询返回的结果对象在访问对象及其字段时会延迟加载它们.您的对象永远不会被复制,因此只能在内存/磁盘中代表一次.

The cool thing is that you don't need to worry about that with Realm. The result object returned from a query is lazily loading the objects and its fields when you access them. Your objects are never copied and thus only represented once in memory/disk.

此操作的(当前)实现细节是,从查询返回的RealmResults对象只是对匹配对象的引用的列表.这些引用是很小的数字,它们被压缩存储,因此占用很少的内存.因此,即使有100.000个匹配,它实际上也不会占用太多内存.不管它们有一个int字段还是数百个带有字符串或大二进制文件的字段,它都会为所有类型的对象占用相同数量的内存.

The (current) implementation detail of this is that the RealmResults object returned from a query is just a list of references to the matching objects. Those references are tiny numbers which are stored compressed so they take up very little memory. So even with 100.000 matches it actually wouldn't take up much memory. And it would take up the same amount of memory for all kind of objects, whether they have one int field or hundreds of fields with strings or big binaries.

这篇关于限制领域结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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