Which is the fastest way to load the contents of a DBF into an Array.
Something faster than this:
SELECT ("CUSTOMER")
DbGoTop()
do while !eof()
aadd(myarray, CUSTOMER->NAME)
dbskip()
enddoThank you
SELECT ("CUSTOMER")
DbGoTop()
do while !eof()
aadd(myarray, CUSTOMER->NAME)
dbskip()
enddoDid you try dbEval( { || aadd(myarray, CUSTOMER->NAME) } )?
Thank you, but it takes one more second!!!.
aData := {}
ASizeAlloc( aData, CUSTOMER->( LASTREC() ) )All good stuff that Rao pointed out.
Here are some more ideas.
When the data is static, or relatively so, consider loading the data into a static array at the start of the app or of a routine that will be using the data multiple times. Thus the data is only loaded once.
Anytime the computer appears to have hung, or gone into limbo, users will be frustrated. If you can provide some visual feedback that makes the computer appear to be working when it is doing something like loading data, then the users will more easily accept the delay. Note that visual feedback will actually slow down the process due to the increased CPU work, but the users will accept this more easily than no visual feedback.
Regards,
James
Thank you for all your ideas.
Unfortunately, data is not static, so I can´t load at startup.
I thought it was a C level alternative.
Hi,
Maybe you need to change the process. If system is very slow i assume is a result to load a big table and my question for u is... It's necessary ?
As Carles says, "Is it necessary?"
Can you just access the database directly using an index and/or filters?
How big is the array? How long is it taking to load it?
I don't think C could help much, because most of the time is spent reading the disk which is hardware dependent.
Regards,
James
I don't think C could help much, because most of the time is spent reading the disk which is hardware dependent.
FUNCTION AGG_REC( cFile, aFile, nRecord )
LOCAL cDelete
LOCAL aRec := {}
LOCAL nFld, nNew
LOCAL nNuovi
LOCAL aNew := {}
LOCAL nStart := LEN( aFile )
LOCAL i
// se ci sono nuovi record prima crea i nuovi elementi dell'array vuoti
// if there are new records at first create new empty elements
IF nRecord > LEN( aFile )
nNuovi := nRecord - LEN( aFile )
FOR nNew := 1 TO nNuovi
aRec := {}
FOR nFld := 1 TO FCount()
IF fieldtype( nFld ) = "C" .OR. fieldtype( nFld ) = "M"
AADD( aRec , "" )
ENDIF
NEXT i
AADD( aFile , aRec )
AADD( aNew , nStart + nNew )
NEXT nNew
ELSE
AADD( aNew , nRecord )
ENDIF
SELECT &cFile
FOR nNew := 1 TO LEN( aNew )
i := aNew[ nNew ]
GOTO aNew[ nNew ]
aFile[ i , U_DELETE ] := cDelete
aFile[ i , U_DELETE ] := " "
aRec := {}
AADD( aRec , IIF( DELETED() , "D", " " ) )
FOR nFld := 1 TO FCount()
IF fieldtype( nFld ) = "C" .OR. fieldtype( nFld ) = "M"
AADD( aRec , UPPER( fieldget( nFld ) ) )
ENDIF
NEXT i
FOR nFld := 1 TO LEN( aFile[ i ] )
IF aFile[ i , nFld ] <> aRec[ nFld ]
aFile[ i , nFld ] := aRec[ nFld ]
ENDIF
NEXT nFld
NEXT nNew
RETURN NILMarco ,
have you tried with INDEX TEMPORARY and work in the DBF ? are very faster .
Maurizio
Are you using xHarbour.com professional or enterprise? If so, you can use FTS (Fast Text Search) to index and search all or part of data file while sharing with other users.
Thank you very much.
I am using Harbour and I won´t change to xHarbour.
I need the Array in order to use the Autoget feature.