What's the best way to implement variable length arrays?
I want to store a large result set from a database in memory. Each entry is variable in length and access times should be as fast as arrays. What's the best way to accomplish this? I was thinking about keeping the offsets in a separate table and keeping all records consistent? This is strange? (Programming language: Delphi)
source to share
Not sure if I'm completely following you, but take a look at TList.
In Delphi 7, at least it is implemented as pointer coercion. You can use the capacity property to pre-allocate the list ahead of time if you know how many results are returned.
The list will automatically grow if there is a gap in it. How much it grows depends on how long the list is.
Take a look at the source for the unit of classes to see what it does.
Edit: Also D2009 adds genist support to TList, which makes it more enjoyable to use.
source to share
Why not use the MEMORY version of your database? Most have a way to keep a complete table in memory, usually using the SQL MEMORY keyword. You have copied the table from disk to memory table and then you can use all normal memory-speed database operations. I know this works well in DBISAM.
source to share