Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 10/21/2017 in all areas

  1. xan

    Fifteen Game Autoit

    Local $mx, $b[16], $bx[16], $by[16], $bn[16], $win, $enf, $rnd[16], $fr, $loop, $nMsg mix() While $nMsg <> -3 $nMsg = GUIGetMsg() If $nMsg = $mx Then mix() ; Botão mix If Not $loop Then For $i = 0 To 15 ; movimenta os botões selecionados Switch $nMsg Case $b[$i] GUICtrlSetBkColor($b[$i], 0x00cc33) Sleep(190) GUICtrlSetBkColor($b[$i], 0xffffff) if $i = 0 or $i = 4 Or $i = 8 Or $i = 12 Then pos($i, 2, 1, 1) if $i = 1 or $i = 5 Or $i = 9 Or $i = 13 Then pos($i, 1, 1, 1) if $i = 2 or $i = 6 Or $i = 10 Or $i = 14 Then pos($i, 0, 1, 1) if $i = 1 or $i = 5 Or $i = 9 Or $i = 13 Then pos($i, 0, -1, -1) if $i = 2 or $i = 6 Or $i = 10 Or $i = 14 Then pos($i, 1, -1, -1) if $i = 3 or $i = 7 Or $i = 11 Or $i = 15 Then pos($i, 2, -1, -1) if $i < 4 Then pos($i, 2, 4, 4) if $i > 3 And $i < 8 Then pos($i, 1, 4, 4) if $i > 7 And $i < 12 Then pos($i, 0, 1, 4) if $i > 3 And $i < 8 Then pos($i, 0, -4, -4) if $i > 7 And $i < 12 Then pos($i, 1, -4, -4) if $i > 11 Then pos($i, 2, -4, -4) Case -3 Exit EndSwitch GUICtrlSetPos($b[$i], $bx[$i], $by[$i]) ; Atualiza as posições dos botões If $bn[$i] <> $i + 1 Then $win = 1 ; Verifica se os botãoes estão ordenados Next EndIf If Not $win Then ; Animaçã da vitória If $loop < 2 Then For $i = 0 To 30 If $i < 16 Then GUICtrlSetBkColor($b[$i], Random(100, 10000, 1) * 5572 + $i * Random(100, 10000, 1)) If $i > 15 Then GUICtrlSetBkColor($b[$i-16], 0xffffff) Beep(Random(30, 100, 1) * $i, 250) Next EndIf $loop += 1 EndIf $win = 0 WEnd Func pos($n, $p, $sinal, $step) ; combinação para movimento dos botões For $i = $p To 0 Step - 1 if $bn[$n + $sinal * $i + $step] = 16 Then $aux = $b[$n + $sinal * $i] $b[$n + $sinal * $i]= $b[$n + $sinal * $i + $step] $b[$n + $sinal * $i + $step] = $aux $aux = $bn[$n + $sinal * $i] $bn[$n + $sinal * $i] = $bn[$n + $sinal * $i + $step] $bn[$n + $sinal * $i + $step] = $aux EndIf Next $nMsg = 0 EndFunc Func mix() ;Cria e embaralha os botões GUIDelete($fr) $fr = GUICreate("Autoit", 510, 560, 300, 50) GUISetBkColor(0xe8c70e) GUICtrlCreateLabel("JOGO DOS 15", 30, 15, 430, 70, 1) GUICtrlSetFont(-1, 54, 800, 0, "MS Sans Serif") $bt = GUICtrlCreateButton("", 38, 78, 434, 429) GUIctrlSetState(-1,128) $mx = GUICtrlCreateLabel("M i x", 422, 530, 50, 20, 1, 1) GUISetState() For $i = 0 To 3 ;gera as posições dos botões For $j = 0 To 3 $bx[$j + $i * 4] = $i * 3 + $j * 110 + 40 - 3 * $i $by[$j + $i * 4] = $i * 3 + $i * 105 + 80 Next Next $win = 0 $loop = 0 For $i = 0 to 15 Do $b[$i] = 0 $enf = 1 $rnd[$i] = Random(0, 15, 1) For $j = 0 To $i For $k = 0 To $i If $j <> $k And $rnd[$k] = $rnd[$j] Then $enf = 0 Next Next Until $enf $bn[$i] = $rnd[$i] + 1 If $rnd[$i] < 15 Then $b[$i] = GUICtrlCreateButton($rnd[$i] + 1, $bx[$i], $by[$i], 100, 100) GUICtrlSetBkColor($b[$i], 0xffffff) GUICtrlSetFont($b[$i], 50, 800, 0, "MS Sans Serif") EndIf Next EndFunc
    1 point
  2. Optimizing C# and VB code Index based sorting The examples in post 4 is an introduction to threading. The examples here shows how VB code can be optimized using multithreading. The examples are a continuation of the code in post 2 regarding index based sorting. Multithreaded sorting The idea is that if 4 threads are used to sort 100,000 rows, the first thread can sort the first 25,000 rows, the next thread can sort the next 25,000 rows, etc. It results in 4 indexes that finally can be combined into one big index. This is the code in Sort2DArrayOptEx.vb: Imports System Imports System.Threading Imports System.Collections Class SortArrayClass Dim aObjects, aCompare As Object(,) Dim iPartRows, iRestRows, iCmps As Integer Dim iThreads = 4, aIndex(iThreads)(), aRows(iThreads) As Integer Public Function Sort2DArray( aObjPar As Object(,), aCompPar As Object(,) ) As Integer() aObjects = aObjPar : aCompare = aCompPar Dim iRows As Integer = aObjects.GetUpperBound(1) + 1 iRestRows = iRows Mod iThreads : iPartRows = ( iRows - iRestRows ) / iThreads iCmps = aCompare.GetUpperBound(1) + 1 'Multithreaded index based sorting Dim th0 As New Thread( AddressOf Sort2DArraySub ) : th0.Start(0) Dim th1 As New Thread( AddressOf Sort2DArraySub ) : th1.Start(1) Dim th2 As New Thread( AddressOf Sort2DArraySub ) : th2.Start(2) Dim th3 As New Thread( AddressOf Sort2DArraySub ) : th3.Start(3) 'Main thread sleeps until sorting is done While aRows(0) = 0 Or aRows(1) = 0 Or aRows(2) = 0 Or aRows(3) = 0 Thread.Sleep(20) End While 'Combine four indexes into one Dim aIndexAll(iRows-1) As Integer Dim aIndexIdx(iThreads), iLeft, iRight, r, j As Integer For i As Integer = 0 To iRows - 1 iLeft = If( aIndexIdx(0) < aRows(0), 0, If( aIndexIdx(1) < aRows(1), 1, If( aIndexIdx(2) < aRows(2), 2, 3 ) ) ) iRight = iLeft While iRight < iThreads iRight += 1 Select iRight Case 1 iRight = If( aIndexIdx(1) < aRows(1), 1, If( aIndexIdx(2) < aRows(2), 2, If( aIndexIdx(3) < aRows(3), 3, iThreads ) ) ) Case 2 iRight = If( aIndexIdx(2) < aRows(2), 2, If( aIndexIdx(3) < aRows(3), 3, iThreads ) ) Case 3 iRight = If( aIndexIdx(3) < aRows(3), 3, iThreads ) End Select If iRight = iThreads Then Exit While r = 0 'Compare result (-1,0,1) j = 0 'Index in $aCompare array While r = 0 And j < iCmps r = If( aCompare(1,j), String.Compare( aObjects(aCompare(0,j),aIndex(iLeft)(aIndexIdx(iLeft))), aObjects(aCompare(0,j),aIndex(iRight)(aIndexIdx(iRight))) ), If( aObjects(aCompare(0,j),aIndex(iLeft)(aIndexIdx(iLeft))) < aObjects(aCompare(0,j),aIndex(iRight)(aIndexIdx(iRight))), -1, If( aObjects(aCompare(0,j),aIndex(iLeft)(aIndexIdx(iLeft))) > aObjects(aCompare(0,j),aIndex(iRight)(aIndexIdx(iRight))), 1, 0 ) ) ) * aCompare(2,j) j += 1 End While Select r Case 1 iLeft = iRight Case 0 If aIndex(iLeft)(aIndexIdx(iLeft)) > aIndex(iRight)(aIndexIdx(iRight)) Then iLeft = iRight End Select End While aIndexAll(i) = aIndex(iLeft)(aIndexIdx(iLeft)) aIndexIdx(iLeft) += 1 Next Return aIndexAll End Function 'Multithreaded index based sorting Private Sub Sort2DArraySub( oThread As Object ) Dim iThread As Integer = CInt( oThread ) Dim iFirstRow As Integer = If( iThread < iRestRows, iPartRows * iThread + iThread, iPartRows * iThread + iRestRows ) Dim iLastRow As Integer = iFirstRow + If( iThread < iRestRows, iPartRows, iPartRows - 1 ) Dim iRows As Integer = iLastRow - iFirstRow + 1 Dim MyList As New Generic.List( Of Integer ) MyList.Capacity = iRows MyList.Add(iFirstRow) 'Sorting by multiple columns Dim lo, hi, mi, r, j As Integer For i As Integer = iFirstRow + 1 To iLastRow lo = iFirstRow hi = i - 1 Do r = 0 'Compare result (-1,0,1) j = 0 'Index in $aCompare array mi = ( lo + hi ) / 2 While r = 0 And j < iCmps r = If( aCompare(1,j), String.Compare( aObjects(aCompare(0,j),i), aObjects(aCompare(0,j),MyList.Item(mi-iFirstRow)) ), If( aObjects(aCompare(0,j),i) < aObjects(aCompare(0,j),MyList.Item(mi-iFirstRow)), -1, If( aObjects(aCompare(0,j),i) > aObjects(aCompare(0,j),MyList.Item(mi-iFirstRow)), 1, 0 ) ) ) * aCompare(2,j) j += 1 End While Select r Case -1 hi = mi - 1 Case 1 lo = mi + 1 Case 0 Exit Do End Select Loop Until lo > hi MyList.Insert( If(lo=mi+1,mi+1,mi)-iFirstRow, i ) Next aIndex(iThread) = MyList.ToArray() aRows(iThread) = iRows End Sub End Class In Runtimes.au3 the execution times for sorting arrays with different number of rows are measuered for pure AutoIt code, for optimized VB code and for multithreaded VB code. This is the results on my PC: Code executed as 32 bit code Code executed as 64 bit code ============================ ============================ $iRows = 100, 6 columns $iRows = 100, 6 columns Sort array by columns 0, 1, 2 Sort array by columns 0, 1, 2 ----------------------------------- ----------------------------------- Pure AutoIt code: 4.3340 Pure AutoIt code: 3.7655 Optimized VB code: 1.2553 Optimized VB code: 1.4281 Multithreaded VB code: 19.0067 Multithreaded VB code: 33.5323 $iRows = 500, 6 columns $iRows = 500, 6 columns Sort array by columns 0, 1, 2 Sort array by columns 0, 1, 2 ----------------------------------- ----------------------------------- Pure AutoIt code: 27.5916 Pure AutoIt code: 25.5753 Optimized VB code: 2.6330 Optimized VB code: 2.8050 Multithreaded VB code: 31.2496 Multithreaded VB code: 36.4108 $iRows = 1000, 6 columns $iRows = 1000, 6 columns Sort array by columns 0, 1, 2 Sort array by columns 0, 1, 2 ----------------------------------- ----------------------------------- Pure AutoIt code: 106.4464 Pure AutoIt code: 90.3135 Optimized VB code: 35.7356 Optimized VB code: 27.4234 Multithreaded VB code: 64.3406 Multithreaded VB code: 57.4474 $iRows = 2000, 6 columns $iRows = 2000, 6 columns Sort array by columns 0, 1, 2 Sort array by columns 0, 1, 2 ----------------------------------- ----------------------------------- Pure AutoIt code: 142.1940 Pure AutoIt code: 134.2208 Optimized VB code: 11.6813 Optimized VB code: 10.9643 Multithreaded VB code: 30.2622 Multithreaded VB code: 33.4628 $iRows = 5000, 6 columns $iRows = 5000, 6 columns Sort array by columns 0, 1, 2 Sort array by columns 0, 1, 2 ----------------------------------- ----------------------------------- Pure AutoIt code: 401.1128 Pure AutoIt code: 365.6661 Optimized VB code: 38.3885 Optimized VB code: 31.2551 Multithreaded VB code: 79.6997 Multithreaded VB code: 89.7060 $iRows = 10000, 6 columns $iRows = 10000, 6 columns Sort array by columns 0, 1, 2 Sort array by columns 0, 1, 2 ----------------------------------- ----------------------------------- Pure AutoIt code: 826.2889 Pure AutoIt code: 691.7514 Optimized VB code: 70.5041 Optimized VB code: 65.1964 Multithreaded VB code: 89.2076 Multithreaded VB code: 60.4300 $iRows = 20000, 6 columns $iRows = 20000, 6 columns Sort array by columns 0, 1, 2 Sort array by columns 0, 1, 2 ----------------------------------- ----------------------------------- Pure AutoIt code: 1816.3940 Pure AutoIt code: 1517.2513 Optimized VB code: 183.4977 Optimized VB code: 151.7480 Multithreaded VB code: 150.1049 Multithreaded VB code: 135.3445 $iRows = 50000, 6 columns $iRows = 50000, 6 columns Sort array by columns 0, 1, 2 Sort array by columns 0, 1, 2 ----------------------------------- ----------------------------------- Pure AutoIt code: 5386.5884 Pure AutoIt code: 4239.2327 Optimized VB code: 602.9203 Optimized VB code: 471.3676 Multithreaded VB code: 373.1342 Multithreaded VB code: 371.5393 $iRows = 100000, 6 columns $iRows = 100000, 6 columns Sort array by columns 0, 1, 2 Sort array by columns 0, 1, 2 ----------------------------------- ----------------------------------- Pure AutoIt code: 12798.0606 Pure AutoIt code: 9489.1929 Optimized VB code: 1590.7280 Optimized VB code: 1273.4829 Multithreaded VB code: 800.1118 Multithreaded VB code: 684.8815 $iRows = 250000, 6 columns $iRows = 250000, 6 columns Sort array by columns 0, 1, 2 Sort array by columns 0, 1, 2 ----------------------------------- ----------------------------------- Pure AutoIt code: 44781.3723 Pure AutoIt code: 27407.9705 Optimized VB code: 7217.6899 Optimized VB code: 5222.3106 Multithreaded VB code: 2330.1729 Multithreaded VB code: 1914.2506 $iRows = 500000, 6 columns $iRows = 500000, 6 columns Sort array by columns 0, 1, 2 Sort array by columns 0, 1, 2 ----------------------------------- ----------------------------------- Pure AutoIt code: 128479.2462 Pure AutoIt code: 69438.5295 Optimized VB code: 25016.8543 Optimized VB code: 16692.2426 Multithreaded VB code: 5949.0161 Multithreaded VB code: 4565.7862 $iRows = 750000, 6 columns $iRows = 750000, 6 columns Sort array by columns 0, 1, 2 Sort array by columns 0, 1, 2 ----------------------------------- ----------------------------------- Pure AutoIt code: 250176.5552 Pure AutoIt code: 107785.2414 Optimized VB code: 54193.4737 Optimized VB code: 35217.0613 Multithreaded VB code: 10827.3308 Multithreaded VB code: 8186.0242 $iRows = 1000000, 6 columns $iRows = 1000000, 6 columns Sort array by columns 0, 1, 2 Sort array by columns 0, 1, 2 ----------------------------------- ----------------------------------- Pure AutoIt code: 408457.7649 Pure AutoIt code: 162282.8254 Optimized VB code: 96291.4960 Optimized VB code: 62412.9602 Multithreaded VB code: 17399.9110 Multithreaded VB code: 12690.8546 $iRows = 2000000, 6 columns $iRows = 2000000, 6 columns Sort array by columns 0, 1, 2 Sort array by columns 0, 1, 2 ----------------------------------- ----------------------------------- Pure AutoIt code: 1445235.5246 Pure AutoIt code: 498648.9821 Optimized VB code: 409872.8400 Optimized VB code: 282116.6518 Multithreaded VB code: 63527.4207 Multithreaded VB code: 51087.1290 Code is added to "Examples\5) Optimizing C# and VB code\1) Index based sorting\" in zip-file in bottom of first post. Implementing a progress bar Another advantage of performing the sorting in 4 worker threads is that the main thread can be released by the VB code and thereby making the AutoIt code responsive while the sorting is going on. This makes it possible to implement a progress bar in the AutoIt code. The code in Sort2DArrayOptEx2.vb is changed a little bit: Imports System Imports System.Threading Imports System.Collections Class SortArrayClass Dim aObjects, aCompare As Object(,) Dim iRows, iPartRows, iRestRows, iCmps As Integer Dim iThreads = 4, aIndex(iThreads)(), aRows(iThreads) As Integer Public Sub Sort2DArray( aObjPar As Object(,), aCompPar As Object(,) ) aObjects = aObjPar : aCompare = aCompPar : iRows = aObjects.GetUpperBound(1) + 1 iRestRows = iRows Mod iThreads : iPartRows = ( iRows - iRestRows ) / iThreads iCmps = aCompare.GetUpperBound(1) + 1 'Multithreaded index based sorting Dim th0 As New Thread( AddressOf Sort2DArraySub ) : th0.Start(0) Dim th1 As New Thread( AddressOf Sort2DArraySub ) : th1.Start(1) Dim th2 As New Thread( AddressOf Sort2DArraySub ) : th2.Start(2) Dim th3 As New Thread( AddressOf Sort2DArraySub ) : th3.Start(3) End Sub 'Multithreaded index based sorting Private Sub Sort2DArraySub( oThread As Object ) Dim iThread As Integer = CInt( oThread ) Dim iFirstRow As Integer = If( iThread < iRestRows, iPartRows * iThread + iThread, iPartRows * iThread + iRestRows ) Dim iLastRow As Integer = iFirstRow + If( iThread < iRestRows, iPartRows, iPartRows - 1 ) Dim iSubRows As Integer = iLastRow - iFirstRow + 1 Dim MyList As New Generic.List( Of Integer ) MyList.Capacity = iSubRows MyList.Add(iFirstRow) 'Sorting by multiple columns Dim lo, hi, mi, r, j As Integer For i As Integer = iFirstRow + 1 To iLastRow lo = iFirstRow hi = i - 1 Do r = 0 'Compare result (-1,0,1) j = 0 'Index in $aCompare array mi = ( lo + hi ) / 2 While r = 0 And j < iCmps r = If( aCompare(1,j), String.Compare( aObjects(aCompare(0,j),i), aObjects(aCompare(0,j),MyList.Item(mi-iFirstRow)) ), If( aObjects(aCompare(0,j),i) < aObjects(aCompare(0,j),MyList.Item(mi-iFirstRow)), -1, If( aObjects(aCompare(0,j),i) > aObjects(aCompare(0,j),MyList.Item(mi-iFirstRow)), 1, 0 ) ) ) * aCompare(2,j) j += 1 End While Select r Case -1 hi = mi - 1 Case 1 lo = mi + 1 Case 0 Exit Do End Select Loop Until lo > hi MyList.Insert( If(lo=mi+1,mi+1,mi)-iFirstRow, i ) If ( i - iFirstRow ) Mod 1000 = 0 Then aRows(iThread) = i - iFirstRow Next aIndex(iThread) = MyList.ToArray() aRows(iThread) = iSubRows End Sub Public Function Sort2DArrayGetCount() As Integer Return aRows(0) + aRows(1) + aRows(2) + aRows(3) End Function Public Function Sort2DArrayGetIndex() As Integer() 'Combine four indexes into one Dim aIndexAll(iRows-1) As Integer Dim aIndexIdx(iThreads), iLeft, iRight, r, j As Integer For i As Integer = 0 To iRows - 1 iLeft = If( aIndexIdx(0) < aRows(0), 0, If( aIndexIdx(1) < aRows(1), 1, If( aIndexIdx(2) < aRows(2), 2, 3 ) ) ) iRight = iLeft While iRight < iThreads iRight += 1 Select iRight Case 1 iRight = If( aIndexIdx(1) < aRows(1), 1, If( aIndexIdx(2) < aRows(2), 2, If( aIndexIdx(3) < aRows(3), 3, iThreads ) ) ) Case 2 iRight = If( aIndexIdx(2) < aRows(2), 2, If( aIndexIdx(3) < aRows(3), 3, iThreads ) ) Case 3 iRight = If( aIndexIdx(3) < aRows(3), 3, iThreads ) End Select If iRight = iThreads Then Exit While r = 0 'Compare result (-1,0,1) j = 0 'Index in $aCompare array While r = 0 And j < iCmps r = If( aCompare(1,j), String.Compare( aObjects(aCompare(0,j),aIndex(iLeft)(aIndexIdx(iLeft))), aObjects(aCompare(0,j),aIndex(iRight)(aIndexIdx(iRight))) ), If( aObjects(aCompare(0,j),aIndex(iLeft)(aIndexIdx(iLeft))) < aObjects(aCompare(0,j),aIndex(iRight)(aIndexIdx(iRight))), -1, If( aObjects(aCompare(0,j),aIndex(iLeft)(aIndexIdx(iLeft))) > aObjects(aCompare(0,j),aIndex(iRight)(aIndexIdx(iRight))), 1, 0 ) ) ) * aCompare(2,j) j += 1 End While Select r Case 1 iLeft = iRight Case 0 If aIndex(iLeft)(aIndexIdx(iLeft)) > aIndex(iRight)(aIndexIdx(iRight)) Then iLeft = iRight End Select End While aIndexAll(i) = aIndex(iLeft)(aIndexIdx(iLeft)) aIndexIdx(iLeft) += 1 Next Return aIndexAll End Function End Class In Progressbar.au3 the execution times are measuered for the new code. This is the results on my PC when the code is run as 64 bit code: 250,000 rows Generate array Array generated 782.829209100278 Start sorting ... Sorting started 1052.33601879453 Sorting finished 3112.24138122098 Get index ... Index received 628.809605602899 500,000 rows Generate array Array generated 1692.53510123118 Start sorting ... Sorting started 1736.08362238057 Sorting finished 5300.57901794125 Get index ... Index received 987.373807333858 750,000 rows Generate array Array generated 2701.3300790124 Start sorting ... Sorting started 2846.97747093829 Sorting finished 8147.51853411496 Get index ... Index received 1427.32770753222 1,000,000 rows Generate array Array generated 3671.26491871585 Start sorting ... Sorting started 3360.98083976994 Sorting finished 11515.8238123206 Get index ... Index received 1913.89753875819 2,000,000 rows Generate array Array generated 7789.33304890347 Start sorting ... Sorting started 6773.98630303971 Sorting finished 48250.9211649065 Get index ... Index received 3852.50335220913 Note the lines titled "Sorting started". These are the lines that measure the time it takes to execute this code: Public Sub Sort2DArray( aObjPar As Object(,), aCompPar As Object(,) ) aObjects = aObjPar : aCompare = aCompPar : iRows = aObjects.GetUpperBound(1) + 1 iRestRows = iRows Mod iThreads : iPartRows = ( iRows - iRestRows ) / iThreads iCmps = aCompare.GetUpperBound(1) + 1 'Multithreaded index based sorting Dim th0 As New Thread( AddressOf Sort2DArraySub ) : th0.Start(0) Dim th1 As New Thread( AddressOf Sort2DArraySub ) : th1.Start(1) Dim th2 As New Thread( AddressOf Sort2DArraySub ) : th2.Start(2) Dim th3 As New Thread( AddressOf Sort2DArraySub ) : th3.Start(3) End Sub Most of the time is spent by passing the array ($aArray) as a parameter from the AutoIt code to the VB method (in aObjPar). Code is added to "Examples\5) Optimizing C# and VB code\1) Index based sorting\" in zip-file in bottom of first post. Global array variable Post 2 is a UDF version of four examples about generating a 2D array of random data, sorting the array by one or more columns through an index, converting the 2D array to a 1D array in CSV format, and finally saving the 1D array as a CSV file. The code is stored in "Examples\3) UDF version of examples\" in zip-file in bottom of first post. I've added a new example, ExampleOpt2.au3, to the Examples folder, where the execution times and the total execution time for these 4 procedures are measured for an array with 250,000 rows. This is the results: Code executed as 32 bit code Code executed as 64 bit code ============================ ============================ 250000 rows 250000 rows Generate array: 995.724559926393 Generate array: 797.652719123923 Sort array: 7236.27375117504 Sort array: 5291.30258795446 Convert array: 1426.65439887983 Convert array: 1224.09933028633 Save array: 450.983570086659 Save array: 383.220670832949 Total time: 10109.6362800679 Total time: 7696.27530819767 At the bottom of the example above we saw that quite a lot of time is being used to transfer arrays between the AutoIt code and the VB code. One way to avoid the time used to transfer arrays between AutoIt code and VB code is to store the array ($aArray/aObjects) as a global variable in the VB code. This is implemented in "Examples\5) Optimizing C# and VB code\2) Global array variable\Includes\ArrayFuncsOpt.vb". There is also used a multithreaded version of the sorting code. And the two procedures to convert and save the array as a CSV file is combined into one procedure to avoid transfering the array of strings back and forth. This is the time measurement for the new code: Code executed as 32 bit code Code executed as 64 bit code ============================ ============================ 250000 rows 250000 rows Generate array: 696.800872597593 Generate array: 516.643380589801 Sort array: 1542.99252546023 Sort array: 1465.04082474547 Save array: 446.520844017085 Save array: 418.329314718878 Total time: 2686.31424207491 Total time: 2400.01352005415 Code in "Examples\5) Optimizing C# and VB code\2) Global array variable\" in zip-file in bottom of first post. Delete global variables To delete global variables used in the VB code simply delete the object. The objects are solely handled in Includes\ArrayFuncsOpt.au3 UDF (there are no objects directly in the user code). The $oArrayClass object which is an instance of the ArrayClass in the VB code is created in ArrayFuncsOptInit() in this way: Func ArrayFuncsOptInit( $bDelObj = False ) Static $oNetCode = 0, $oArrayClass = 0 If $bDelObj Then $oArrayClass = 0 $oArrayClass = DotNet_CreateObject( $oNetCode, "ArrayClass" ) Return EndIf If IsObj( $oArrayClass ) Then Return $oArrayClass ; Compile and load VB code, create ArrayClass object $oNetCode = DotNet_LoadVBcode( FileRead( "..\Includes\ArrayFuncsOpt.vb" ), "System.dll" ) $oArrayClass = DotNet_CreateObject( $oNetCode, "ArrayClass" ) Return $oArrayClass EndFunc And the object is deleted in ArrayFuncsDelObject() by calling ArrayFuncsOptInit() with the $bDelObj parameter set to True: Func ArrayFuncsDelObject() ArrayFuncsOptInit( True ) EndFunc When the old object is deleted, a new object is created. ArrayFuncsDelObject() is called in bottom of ExampleOpt2.au3. Similar procedures are used in the example with the progress bar above to delete the old object and create a new.
    1 point
  3. So let me see I understand this: You previously scripted with ahk and now started with AU3 and have no clue about any programming basics. Guess you've only done Cut&Paste programming till now? So, which part of the explanation in the Helpfile do you not understand? Jos
    1 point
  4. Hi, did you resolve the issue?
    1 point
×
×
  • Create New...