假如数据库中有一系列数据在delphi程序中经常用到,而且数据本身每分钟不断在新增。
因为频繁用到,我想设计个多维多态数组,用来记录这些数据,即先通过数据库组件取数据,然后赋给数组。这个思路应该是正确的吧?
要解决数据不断新增,就需要设置定时器不断地刷新数据库组件的数据,然后把新数据追加到动态数组,这就会造成不断变更动态数组的长度,想问下这样会明显影响运行效率吗?

解决方案 »

  1.   

    参见STACKOVERFLOW上的疑问解答:
    http://stackoverflow.com/questions/3183851/can-i-resize-a-delphi-array-without-losing-its-previous-contents
    10     
     Just be aware it can be a memory intensive operation, because the whole array could be moved if there is not enough space to extend it where it is allocated. An array, unlike lists, must be allocated in a contiguos memory block. That's why list (and other containers) exist. Use the best container for you needs. – user160694 Jul 6 '10 at 8:28 
    5     
     @ldsandon: Be careful: Many "lists" in Delphi are implemented as arrays or at least contiguous memory blocks in exactly the same way as an array "under the hood". TList, TObjectList, TStringList... these most commonly encountered lists are all effectively arrays inside object wrappers. The "Length" of these "arrays" has more flexible management tools than "real" arrays however, as they support both Capacity (size of the "array") and Count (number of elements actually being used) so you can pre-allocate the contiguous memory you need (via Capacity) before filling it. – 
    这会明显影响运行效率,使用一个成熟的容器,可能比你自己管理内存更为可靠。
      

  2.   

    用链表 Tlist  记录结构 记录一条记录 
    动态数组要重新分配内存  
      

  3.   

    设置定时器不断地刷新数据库组件的数据
    不用刷新 数据库组件的数据吧 你是怎么刷新的?
      数据一般设有一个自动增加字段ID 把当大于本地最大ID的记录查出来
    增加到list (数组)中即可