gpt4 book ai didi

java - 使用 Room 将二进制文件的链接与元数据一起存储是一种好习惯吗?

转载 作者:行者123 更新时间:2023-11-29 04:19:44 24 4
gpt4 key购买 nike

我想知道您对以下内容的看法:假设您有多个结构化二进制文件(数百个)和一个用于处理它们的库(创建、打开、读取、保存)。您将如何设计一个 Android 应用程序来将其全部包装起来:

  • Would you pack all the binary files in the Zip archive leave files separate in the application directory (subdirectory) ;

  • Would you use Room library to create links (Uri) to those files along with additional information like tags, titles, thumbnail images (also Uri) access them directly and save the extra in metafiles create a extra binary layer for each of the files to store the metadata (binaryWithMeta <- (metadata + binary))

最佳答案

1) Room 只是 SQLite 的包装器,你很幸运,他们已经提出并回答了 BLOB 性能问题。

Internal Versus External BLOBs in SQLite

The matrix below shows the time needed to read BLOBs stored in separate files divided by the time needed to read BLOBs stored entirely in the database. Hence, for numbers larger than 1.0, it is faster to store the BLOBs directly in the database. For numbers smaller than 1.0, it is faster to store the BLOBs in separate files.

enter image description here

We deduce the following rules of thumb from the matrix above:

  • A database page size of 8192 or 16384 gives the best performance for large BLOB I/O.
  • For BLOBs smaller than 100KB, reads are faster when the BLOBs are stored directly in the database file. For BLOBs larger than 100KB, reads from a separate file are faster.

Of course, your mileage may vary depending on hardware, filesystem, and operating system. Double-check these figures on target hardware before committing to a particular design.

来源:https://www.sqlite.org/intern-v-extern-blob.html , 强调我的。

如您所见,SQLite 非常适合存储元数据,甚至是图像缩略图。

2) 其他问题的答案取决于多种因素:

  • 文件大小(可能压缩大文件,可能把小文件放入数据库)
  • 文件类型(不要压缩 MP3、JPG 等)
  • 访问频率(不要压缩经常访问的文件,或缓存它们),
  • 无论您是否必须支持低存储或 RAM 的低端设备,...

是的,需要某种抽象层来优化处理不同条件下的不同类型的文件。没有一个好的答案。

期待可能在 Stack Overflow 上不受欢迎的固执己见的答案。

关于java - 使用 Room 将二进制文件的链接与元数据一起存储是一种好习惯吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50124747/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com