实现可变长度数组的最佳方法是什么?
我想将数据库中的大型结果集存储在内存中。 每条记录的长度都是可变的,访问时间必须与数组一样快。 实现这一点的最佳方法是什么? 我正在考虑将偏移量保存在一个单独的表中并连续存储所有记录? 奇怪吗? (编程语言:Delphi)
I want to store a large result set from database in memory. Every record has variable length and access time must be as fast as arrays. What is the best way to implement this? I was thinking of keeping offsets in a separate table and storing all of the records consecutively? Is it odd? (Programming Language: Delphi)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在 mj2008 之后,您可以使用 TCLientDataset 而不是记录数组。
该结果集有多大?
Following mj2008, you could use a TCLientDataset instead of a record array.
How large is that resultset?
我会使用 TList,并存储指向您的记录的指针。
I'd use TList, and store pointers to your record.
不确定我完全明白你的意思,但看看 TList。
至少在 Delphi 7 中,它是作为指针数组实现的。 如果您知道有多少结果返回,则可以使用容量属性提前预先分配列表。
如果空间不足,该列表将自动增长。 它增长多少取决于列表有多大。
查看类单元的源代码,看看它在做什么。
编辑:同样在 D2009 中,TList 添加了通用支持,这使得它更好用。
Not sure I totally follow you, but have a look at TList.
In Delphi 7 at least, it is implemented as an arrary of pointers. You can use the capacity property to pre allocate the list ahead of time if you know how many results are coming back.
The list will automatically grow if it runs out of space. How much it grows by depends on how big the list is.
Take a look at the source for the classes unit to see what it's doing.
Edit: Also in D2009 genric support was added to TList which makes it a bit nicer to use.
最好的方法可能是包含一个指向记录的指针数组。 在这种情况下,您不必处理偏移量,并且查找将是恒定时间。
The best way is probably to contain an array of pointers to records. You won't have to deal with offsets, in that case, and lookups will be constant time.
为什么不使用数据库的 MEMORY 版本? 大多数都有办法在内存中保存完整的表,通常涉及 SQL 关键字 MEMORY。 您可以将该表从磁盘复制到内存表,然后可以以内存速度使用所有正常的数据库操作。 我知道这在 DBISAM 中效果很好。
Why not use a MEMORY version of your database? Most have a way to keep a complete table in memory, usually involving the SQL keyword MEMORY. You'd copy the table from disk to the memory table, and then can use all the normal database operations at memory speed. I know this works well in DBISAM.