kart442 Posted October 25, 2007 Share Posted October 25, 2007 Can an Array be read completely at one time? How is an Array read for sure anyway? Does an ExitLoop restart the Array also? Is there a way to load the complete Array in memory? Thanks for any help.... Link to comment Share on other sites More sharing options...
weaponx Posted October 25, 2007 Share Posted October 25, 2007 Oh dear. You are going to have to elaborate. "Can an Array be read completely at one time?" ???? Link to comment Share on other sites More sharing options...
kart442 Posted October 25, 2007 Author Share Posted October 25, 2007 Doesn't it read only one line at a time? I want to know if a file read to an array can be loaded fully? Or is there a quicker way for the script to get the elements? Link to comment Share on other sites More sharing options...
weaponx Posted October 25, 2007 Share Posted October 25, 2007 You didn't mention FileReadToArray() in your first post. This function will load the entire contents of a file in one go. Link to comment Share on other sites More sharing options...
kart442 Posted October 25, 2007 Author Share Posted October 25, 2007 I understand that part but it only reads one line at a time when using a "For To Next" right? Is there some other way to get the elements quicker? Link to comment Share on other sites More sharing options...
weaponx Posted October 25, 2007 Share Posted October 25, 2007 The _FileReadToArray() function doesn't actually use a loop. It reads in the file as one long string and uses a StringSplit() to split by @LF Link to comment Share on other sites More sharing options...
kart442 Posted October 25, 2007 Author Share Posted October 25, 2007 I have 4 files being read to Arrays....The more elements I add the slower the script runs. Is there some other way so the script doesn't slow down? Link to comment Share on other sites More sharing options...
weaponx Posted October 25, 2007 Share Posted October 25, 2007 It depends on what is being done with the files. Do you need the entire contents or can you just use FileReadLine? Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 25, 2007 Share Posted October 25, 2007 I have 4 files being read to Arrays....The more elements I add the slower the script runs.Is there some other way so the script doesn't slow down?Have you timed the various functional parts of your script (TimerInit/TimerDiff)? I suspect four calls to _FileReadToArray() are not the slow part, but your loop logic using the arrays. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
kart442 Posted October 25, 2007 Author Share Posted October 25, 2007 OK I see about the exitloops I'll try it without them but prefer to use them. If there is quicker way other that _FileReadToArray please let know. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted October 25, 2007 Moderators Share Posted October 25, 2007 (edited) OK I see about the exitloops I'll try it without them but prefer to use them.If there is quicker way other that _FileReadToArray please let know.You're obviously trying to find something in these files, and they must be pretty hefty.The steps that _FileReadToArray() takes are probably along these lines.1. FileRead: - Read entire file (pretty dog gone fast)2. StringSplit - StringStripCR @LF: - Strip all carriage returns and split the file for each line with Line Feed (pretty dog gone fast)3. Return ArrayNow the above mentioned takes next to no time at all... so as PsaltyDS said... the fault is in your end, for 1 of 2 reasons.1. These files are monsterous.2. Your loop you are using to parse the files, find your string, manipulate the string, twiddle your thumbs, count your toes, then finally return the value is probably not soundly set up.If it is one string you are trying to find... and you have the guts to learn it (On your own through the search engine here and google), StringRegExp() may prove to be a much faster solution to parsing line by line in each file (You'd still have to use FileRead() of course). Edited October 25, 2007 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 25, 2007 Share Posted October 25, 2007 OK I see about the exitloops I'll try it without them but prefer to use them. If there is quicker way other that _FileReadToArray please let know. You don't have to do without anything, just add some TimerInit's and TimerDiff's to show the time taken for each part: 1. _FileReadToArray() and 2. Completing your (search?) loop. That will tell you what to focus on for improvement. And I'm still betting on you loop to manipulate the array AFTER the _FileReadToArray() is done. #include <array.au3> #include <file.au3> ; Four almost identical 20KB log files used for test Dim $avFiles = _ArrayCreate("C:\Temp\Test1.txt", "C:\Temp\Test2.txt", "C:\Temp\Test3.txt", "C:\Temp\Test4.txt") Dim $iReadTime = 0, $iSortTime = 0, $iTime, $avData, $iCount, $sMsg $iCount = UBound($avFiles) For $n = 0 To UBound($avFiles) - 1 $iTime = TimerInit() If _FileReadToArray($avFiles[$n], $avData) Then $iReadTime += TimerDiff($iTime) $iTime = TimerInit() _ArraySort($avData, 0, 1) $iSortTime += TimerDiff($iTime) Else $iCount -= 1 MsgBox(16, "Error", "Error reading file to array: " & $avFiles[$n]) EndIf Next If $iCount Then $sMsg = "Avg time for _FileReadToArray() = " & Round($iReadTime / $iCount, 1) & "ms" & @CRLF & _ "Avg time for _ArraySort() = " & Round($iSortTime / $iCount, 1) & "ms" MsgBox(64, "Results", $sMsg) Else MsgBox(16, "Error", "None of the file operations were successfull = no stats.") EndIf In this test, _FileReadToArray() took about 2.6ms avg, and the sort took 90.2ms avg. Test your code in a similar fashion. Don't guess about what needs optimization. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now