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)

+1


source to share


5 answers


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.

+3


source


The best way is probably to keep an array of pointers to records. In this case, you do not have to deal with offsets, and the search will be constant.



+1


source


I would use TList and store the pointers in your record.

type
  pMyRecord : ^TMyRecord;
...
...
...
var
  p : pMyRecord;
...
...
New(p);
with p^ do
begin
  ...
  ...
end;
...
MyList.Add(P);

      

0


source


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.

0


source


Following mj2008 , you can use TCLientDataset instead of array of records. How big is this result set?

0


source







All Articles