将图像存储在sqlite或只是一个参考? [英] Store images in sqlite or just a reference to it?

查看:224
本文介绍了将图像存储在sqlite或只是一个参考?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用coredata做了几个应用程序,我在sqlite存储图像,但在某个地方,我发现它是坏的。我搜索了网络,但我发现的是这个建议:




  • image size< 100kb 存储在与相关数据相同的表格中

  • 图片大小< 1mb 存储在通过关系
    附加的单独表中,以避免不必要地加载

  • 映像大小> 1mb <因此我的问题是:在sqlite数据库中保存图像的优点和缺点是

> NSData
,并且在图像保存在文件系统中时只存储对图像的引用?

解决方案

p> Apple在 Core Data Performance 。一般来说,虽然SQLite扩展性很好,可以轻松处理大小为数GB的数据库,但是大型二进制Blob不可查询或可索引,并且以很小的回报来扩充数据库的大小。



如果您定位的是iOS 4及更高版本,则可以设置允许外部二进制数据存储标记,包含此类数据的属性,Core Data将自动将它们单独存储在文件系统上(如果它认为合适),并自动管理数据存储中该数据的链接。


I have made couple of apps using coredata and I was storing images in sqlite, but somewhere i found that it is bad. I've searched the net but all I've found is this suggestion:

  • image size < 100kb store in the same table as the relevant data
  • image size < 1mb store in a separate table attached via a relationship to avoid loading unnecessarily
  • image size > 1mb store on disk and reference it inside of Core Data

So my question is: what are pros and cons of saving an image in sqlite db as NSData, and storing just a reference to the image while image is saved in the file system?

解决方案

Apple provide some guidance on this topic in their guide on Core Data Performance. In general, although SQLite scales pretty well and can handle databases that are many gigabytes in size with ease, large binary blobs are not queryable or indexable, and inflate the size of the database with little return.

If you're targeting iOS 4 and above, you can set the "Allows External Binary Data Storage" flag on your attributes that contain such data, and Core Data will automatically store them separately on the file system (if it deems appropriate), and automatically manage the link to that data in your data store.

这篇关于将图像存储在sqlite或只是一个参考?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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