在 SQL Lite 中将浮点列表存储在 blob 或文本中是否有意义

发布于 2025-01-08 08:35:19 字数 1072 浏览 6 评论 0原文

我对 iPhone 开发还很陌生,所以很抱歉,如果这是一个愚蠢的问题;)

我有一堆数据用于映射值之间预先计算的关系,

例如

将光输入映射到太阳能电池板的功率输出。

一个比例是固定的,可以很容易地计算(即它以 0.1 为步长上升,并且有一个已知的起点和终点)

0.0 - 80.0

另一种比例是由我以文本格式获得的一些数据定义的:

9.80293622028191E+0000, 9.82985159414126E+0000, 9.85682155471754E+0000、 9.88384617060865E+0000、 9.91092551045114E+0000、 9.93805964292038E+0000、 9.96524863673053E+0000、 9.99249256063480E+0000、 1.00197914834255E+0001、 1.00471454739344E+0001、 1.00745546010324E+0001 等

我可以在手机上使用它来绘制不同变量的线条。

文本格式的总数据约为 4mb(每个数据行约 32kb)

问题是 - 如何最好地存储该浮点值数组,以便我可以轻松更新它 - 并且还可以轻松加载它以进行显示?

我不需要从中挑选出单个值 - 我总是需要给定行的整个列表 - 因此将其存储为单个数据对象似乎是有意义的。我可以将其作为文本保存到文件中,然后在想要更新时覆盖该文件。但是 - 我需要一个 SQL lite 数据库来存储其他数据,这对于存储数据似乎更明智。

在 SQL 中使用浮点数据类型似乎是一种相当繁重的方法 - 因为我总是想要一行的完整值集,因此每个选择都将是一个连接并且(我必须存储订单信息这样我就可以按正确的顺序将它们返回)

将整个数组推入字符串并将其存储为文本是否有意义?或者是否有一种不错的方法将 NSArray 序列化为 blob 字段并稍后重建它?

-----编辑----------

事实证明,SQLite 数据库中的几千行浮点在手机本身上非常慢。在模拟器中没问题,但在手机上加载可能需要 20 秒左右。为了解决这个问题,我将这些数据放入平面文本文件中,并在将其加载到 NSArray 中时将其转换为浮点数。

I'm pretty new to iPhone development - so apologies if this is a dumb question ;)

I have a bunch of data for mapping a pre-calculated relationships between values

e.g.

Mapping light input to power output for a solar panel.

One scale is fixed and can be easily calculated (i.e. it goes up in steps of 0.1 and has a known start and end point)

0.0 - 80.0

The other scale is defined by some data that I have in text format:

9.80293622028191E+0000, 9.82985159414126E+0000, 9.85682155471754E+0000, 9.88384617060865E+0000, 9.91092551045114E+0000, 9.93805964292038E+0000, 9.96524863673053E+0000, 9.99249256063480E+0000, 1.00197914834255E+0001, 1.00471454739344E+0001, 1.00745546010324E+0001 etc

I can use this on the phone to plot the lines for different variables.

The total data in text format is about 4mb (about 32kb per data line)

The question is - how best to store that array of float values such that I can easily update it - and also easily load it up for display?

I don't ever need to pick out a single value from it - I'll always need the whole list for a given line - so it seems to make sense to store it as a single data object. I could save it as text to a file and then overwrite the file when I want to update it. However - I'm going to need a SQL lite db for other data and this seems more sensible for storing data.

Using the float data type in SQL seems to be quite a heavy way to do it - as I'll always want a complete set of values for a line so every select will be a join and (I'll have to store the order info so I can get them back in the right order)

Does it makes sense to push the whole array into a string and store it as Text? Or is there a decent way to serialize an NSArray into a blob field and reconstruct it later?

-----EDIT----------

It turns out that a few thousand rows of floats in the SQLite db is terribly slow on the phone itself. It's ok in the simulator, but can take 20 seconds or so to load on the phone. To get round this I've put this data into flat text files and I convert to floats as I load it into an NSArray.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伴梦长久 2025-01-15 08:35:19

您可以序列化/反序列化您的数组调用:

- (NSArray *)componentsSeparatedByString:(NSString *)separator;

但是

- (NSString *)componentsJoinedByString:(NSString *)separator;

,我建议

1) 将您的数组存储到文件中(writeToFile、arrayWithContentsOfFile)

或更好

2) 将它们逐值写入现有的 SQLite 数据库。如果我没猜错的话,你不需要任何加入。只需使用以下方法获取您的值:

SELECT y FROM data LIMIT start_value, end_value

You can serialize/unserialize your Array calling:

- (NSArray *)componentsSeparatedByString:(NSString *)separator;

and

- (NSString *)componentsJoinedByString:(NSString *)separator;

However, I would recommend either

1) storing your Array into a file (writeToFile, arrayWithContentsOfFile)

or better

2) writing them into your existing SQLite-Database value by value. If I got you right, you don't need any joins. Just fetch your values using:

SELECT y FROM data LIMIT start_value, end_value
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文