database Realm 与 Sqlite 用于移动开发

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37151580/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 08:02:00  来源:igfitidea点击:

Realm vs Sqlite for mobile development

databasesqlitemobilexamarinrealm

提问by Medo Medo

Am an Xamarin Developer , I used to use Sqliteas mobile database ,
recently Realmcomes to the picture.
Any idea about Differences between them in Performance & ease of use..etc?

我是一名 Xamarin 开发人员,我曾经使用Sqlite作为移动数据库,
最近Realm出现了。
对它们在性能和易用性方面的差异有什么想法......等?

What is the best practice of using either one?

使用任何一种的最佳做法是什么?

采纳答案by Mohammed Ali

Realm and Sqlite are quite different in many aspects.

Realm 和 Sqlite 在很多方面都有很大的不同。

Here are two articles you could go through to grasp the main differences:

您可以阅读以下两篇文章以了解主要差异:

System Properties Comparison Realm vs. SQLite
5 Reasons Why You Should Choose Realm Over CoreData/SQLite

系统属性比较 Realm 与 SQLite
选择 Realm 而不是 CoreData/SQLite 的 5 个理由

As suggested by Slavia in the comments, take also a look to this articlefor a comparison of several ORMs, including Realm.

正如 Slavia 在评论中所建议的那样,还可以查看本文以比较包括 Realm 在内的几种 ORM。

回答by Andy Dent

I'm a developer on the Xamarin team at Realm so I can tell you a bit more about how the Xamarin product works.

我是 Realm Xamarin 团队的一名开发人员,所以我可以告诉你更多关于 Xamarin 产品如何工作的信息。

Realm has a C++ core which is common across all products. That is why we release for each platformrather than just a language - we need to include the native core. Whilst we support PCL builds of your code, we don't have a PCL libraryas such - at build time your PCL code will link to the matching IOS or Android library.

Realm 有一个 C++ 核心,它在所有产品中都是通用的。这就是为什么我们为每个平台发布而不仅仅是一种语言——我们需要包含原生核心。虽然我们支持您的代码的 PCL 构建,但我们没有这样的PCL 库- 在构建时您的 PCL 代码将链接到匹配的 IOS 或 Android 库。

All the Realm products are individually developed to provide an idiomatic interface for a given programming language, with as slim a layer as possible between your code and the data.

所有 Realm 产品都是单独开发的,为给定的编程语言提供惯用的接口,在您的代码和数据之间有尽可能薄的层。

That means, for example, the C# product provides LINQ for querying and uses C# objects as the means of defining the data model. At build time, the Fody code generator is run to add property setters and getters so your C# objects will directly interact with the core C++ data. Unlike typical ORM products, there's no copying of data from the database into buffers and then again into your objects.

这意味着,例如,C# 产品提供用于查询的 LINQ,并使用 C# 对象作为定义数据模型的手段。在构建时,Fody 代码生成器会运行以添加属性设置器和获取器,因此您的 C# 对象将直接与核心 C++ 数据交互。与典型的 ORM 产品不同,无需将数据从数据库复制到缓冲区,然后再复制到您的对象中。

Realm data is memory-mapped so it's going directly from your code to storage. We generate accessor methods that replace the auto-property getters and setters.

领域数据是内存映射的,所以它直接从你的代码到存储。我们生成替换自动属性 ​​getter 和 setter 的访问器方法。

We use the term zero-copyto describe this. In contrast, most other systems will have C# objects which have fields backing their properties. Those objects are often populated by copying from a SQLite buffer which has been read from the diskstorage. That's two levels of copying.

我们使用术语零拷贝来描述这一点。相比之下,大多数其他系统将具有 C# 对象,这些对象具有支持其属性的字段。这些对象通常通过从从磁盘存储读取的 SQLite 缓冲区复制来填充。这是两个级别的复制。