TheDcoder Posted May 30, 2015 Posted May 30, 2015 Hello , I know about ReDim but I am confused Local $aArray[4] = [0, 1, 2, 3] Func ExpandArray(ByRef $aArray) ; How? EndFuncThanks in Advance, TD EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
Developers Jos Posted May 30, 2015 Developers Posted May 30, 2015 Confused about what?Did you open the helpfile on Redim and try it?What didn't work?Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
TheDcoder Posted May 30, 2015 Author Posted May 30, 2015 @Jos I can't understand what is this:ReDim $aArray[subscript 1]...[subscript n] EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
TheDcoder Posted May 30, 2015 Author Posted May 30, 2015 Sorry for posting this in GUI help section EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
Developers Jos Posted May 30, 2015 Developers Posted May 30, 2015 I'll move it.So can in the mean time play a little with ReDim so you understand it.Jos Xandy 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
TheDcoder Posted May 30, 2015 Author Posted May 30, 2015 I found out my answer Local $aArray[4] = [0, 1, 2, 3] Func ExpandArray(ByRef $aArray, $iExpandCount) ReDim $aArray[UBound($aArray) + ($iExpandCount - 1)] EndFunc Xandy 1 EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
Developers Jos Posted May 30, 2015 Developers Posted May 30, 2015 (edited) I knew you would, you just need a little push to sort it out by yourself in stead of always asking everything that looks difficult. Jos Edited May 30, 2015 by Jos Xandy 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
TheDcoder Posted May 30, 2015 Author Posted May 30, 2015 Thanks! EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
Moderators Melba23 Posted May 30, 2015 Moderators Posted May 30, 2015 TheDcoder,If you do not know the final size of an array, incrementing it by one each time you add an element is not the best way to go as ReDim is a very slow function. Look at the final example in the Recursion tutorial in the Wiki and the "A little added extra" section below it to see how best you can manage this situation.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
TheDcoder Posted May 30, 2015 Author Posted May 30, 2015 @Melba23 Multiply it? EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
Moderators Melba23 Posted May 30, 2015 Moderators Posted May 30, 2015 TheDcoder,Did you read it the explanation?ReDim is among the slowest of the AutoIt functions, so you want to limit its use as much as possible. If we were to increase the array size by just the one element each time [...], we would slow down the function enormously [...]. Instead of adding a single additional element we double the array in size if it is already full to make sure we get plenty of extra space. You will need to have a count variable available to do this - so why not in the [0] element as is the case for many AutoIt arrays? Just remember that if you want to use the array subsequently [...] you will need one final ReDim to get rid of any unused elements left over after the last increase in size.So yes, you set a reasonable initial size and then multiply the array size by 2 each time you fill it - getting rid of any unused empty elements once you have got the array to the final size. It really does work - give it a try.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
TheDcoder Posted May 30, 2015 Author Posted May 30, 2015 @Melba23 Will implement that Melba EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
TheDcoder Posted May 31, 2015 Author Posted May 31, 2015 I found this awesome function called _ArrayAdd which does the same thing as ExpandArray... I don't know about internal workings of it but It does the job (internal workings should be fine b/c its coded by AutoIt pros) TD EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
Moderators Melba23 Posted May 31, 2015 Moderators Posted May 31, 2015 TheDcoder,If you look inside _ArrayAdd you will see that in essence it is almost the same as your function - and so it suffers the same problem (lots of slow ReDim calls) if you use it to add lots of single elements in a loop. As explained above, the best way to deal with an array of unknown final size increasing by one element at a time is a "large increase in size" algorithm such as the "doubling" one I used in the Recursion tutorial.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
czardas Posted May 31, 2015 Posted May 31, 2015 (edited) I found this awesome function called _ArrayAdd which does the same thing as ExpandArray... I don't know about internal workings of it but It does the job (internal workings should be fine b/c its coded by AutoIt pros) TD Coded by Melba and working quite nicely too. You should calculate the size of the array you need before creating it if that is possible. Otherwise there are various approaches you could adopt depending on the situation. I differ slightly with Melba on one thing though: doubling the size of an array is not always recommended, especially when dealing with large arrays. Sometimes it's better to make an educated guess at the maximum size when using ReDim. Doubling is a good idea in certain circumstances as is the case with the example Melba mentioned. Edited May 31, 2015 by czardas operator64 ArrayWorkshop
TheDcoder Posted May 31, 2015 Author Posted May 31, 2015 @Melba23 I see... ReDim works fine for me in this case (ReDim take 0.01 ms to expand an array by 1 with 200 elements ). So I will stick to _ArrayAdd because I need to expand an array only ~10 times TD EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
jchd Posted May 31, 2015 Posted May 31, 2015 So it's OK in this case. Otherwise, I'd say an expansion factor of ~1.5 is mostly correct in a large number of cases. Doubling the size just seems a little bit too much in my limited experience. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
TheDcoder Posted May 31, 2015 Author Posted May 31, 2015 @jchfd Yeah, 2x seems too much EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
jchd Posted May 31, 2015 Posted May 31, 2015 Here are the first 20 iterations for geometric progressions by 1.5 and 2, both starting at 1: 1, 2, 3, 5, 8, 12, 18, 27, 41, 62, 93, 140, 210, 315, 473, 710, 1065, 1598, 2397, 3596, ... 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, ...As always the success of a strategy depends on your precise context. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
TheDcoder Posted May 31, 2015 Author Posted May 31, 2015 An array with 524288 elements (all empty) would take 3.4 MB of RAM EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
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