Re: Optimum (fastest) way of storing LV data into file ?

Tech-Archive recommends: Fix windows errors by optimizing your registry



"Dmitriy Antonov" <antonovdima@xxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:eLdj3KgoGHA.3900@xxxxxxxxxxxxxxxxxxxxxxx

"Jack" <notreplyto@it> wrote in message
news:%23AiZ3qfoGHA.2112@xxxxxxxxxxxxxxxxxxxxxxx
Hello,

The ListViewA (visible) has fixed number of colums: 49
and variable number of rows (500 to 1000).
The ListViewB (not visible) has the same number of columns and rows as
ListViewA and contains additional data.
I need to store data (text) kept in both ListViewA and ListViewB, when
application closes, and load it back when application starts.
There is no need for another outside application to 'look' into that
stored data.
The only criteria I worry about is speed.
Right now, using my code it takes about 5-7 minutes to save data (on 3.2
GHz CPU !!!!) and 3-5 minutes to load it back.
Also, I have noticed (I display a progress bar) that data is being saved
much faster at the beginning and gets much slower when progressing.
It is possible that data density is not the same but I do not think that
is a factor.

My code:
===========================
Dim itms(1 To 2) As ListItems

Set itms(1) = .lvEPG(1).ListItems
Set itms(2) = .lvEPG(2).ListItems
Char134 = Chr(134)
Char135 = Chr(135)
Char140 = Chr(140)

FileNum = FreeFile
Open App.Path & "\Data\" & FileName For Binary As FileNum

For i = 1 To itms(1).Count
Title = vbNullString
Desc = vbNullString

For j = 2 To 49
Title = Title & itms(2)(Chan).SubItems(j) & Char134
lpString = itms(1)(itms(2)(Chan).Key).SubItems(j) 'desc
Desc = Desc & lpString & Char134
Next

Title = Title & Char135 & Desc & Char135 & Char140
Put #FileNum, , Title
Next

Close FileNum
=====================EofCode============

I am using Char134, Char135 & Char140 as the markers. They are being used
during loading procedure to put data into the respective fields.


Any comments how to optimize that code and speed up execution deeply
appreciated,
Jack


Ever heard rumor about problems with string concatenation? Try to use Mid
statement instead (or, at least, use parentheses to concatenate small
strings to each other first and than append them to bigger string).
Additionally I would use local variable for each item instead of using
index. Same true for .Key - use local variable for it. BTW, I don't see
how you actually increment that index (what is that Chan variable and how
it is connected to i).
When properly tuned, this task should take less than a second or, at
least, some seconds (depending on amount of data), as I think.

Dmitriy.


In addition to what Dmitriy suggested, File I/O performs better when you
read or write several KB at a time. So try around 4096 bytes buffer, more or
less. Also, uncomment the "Put" statement from your code to see how much
time spent on File I/O and looping...



.



Relevant Pages

  • Re: Optimum (fastest) way of storing LV data into file ?
    ... ListViewA and contains additional data. ... Put #FileNum,, Title ... Ever heard rumor about problems with string concatenation? ... strings to each other first and than append them to bigger string). ...
    (microsoft.public.vb.general.discussion)
  • Optimum (fastest) way of storing LV data into file ?
    ... ListViewA and contains additional data. ... I have noticed (I display a progress bar) that data is being saved ... Title = vbNullString ... Put #FileNum,, Title ...
    (microsoft.public.vb.general.discussion)