Jump to content



Photo

clearing Array

Array

  • Please log in to reply
5 replies to this topic

#1 hezi

hezi

    Seeker

  • Active Members
  • 34 posts

Posted 09 January 2012 - 03:37 PM

is there fast and nice way to clear array? (clear all elements and probably free some memory....)
i can loop to delete element until end but i look for more elegant way :)
maybe delete and recreate array (if possible didnt find this option)


thanks!







#2 Melba23

Melba23

    I'm old - what's your excuse?

  • Moderators
  • 23,002 posts

Posted 09 January 2012 - 03:42 PM

hezi,

Just redeclare the array and it is emptied for you: :)
#include <Array.au3> Global $aArray[3] = [1, 2, 3] _ArrayDisplay($aArray) Global $aArray[3] _ArrayDisplay($aArray)

If you want to get rid of the array completely, just declare it as a simple variable - $aArray = 0. ;)

M23
My UDFs:
Spoiler

#3 hezi

hezi

    Seeker

  • Active Members
  • 34 posts

Posted 09 January 2012 - 03:46 PM

Cool !

thanks for quick reply!

Thanks Melba23

#4 guinness

guinness

    all-consuming swarm in inconspicuous disguise

  • Developers
  • 18,149 posts

Posted 09 January 2012 - 03:53 PM

Another approach that will pass the Au3Check with advanced parameters >>

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <Array.au3> Global $aArray[3] = [1, 2, 3] Global $aBackup[UBound($aArray)] ; Create a blank array. _ArrayDisplay($aArray) $aArray = $aBackup _ArrayDisplay($aArray)

UDF List:
Spoiler
Updated: 31/03/2015

#5 guinness

guinness

    all-consuming swarm in inconspicuous disguise

  • Developers
  • 18,149 posts

Posted 09 January 2012 - 04:11 PM

Or another way is this >>

AutoIt         
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <Array.au3> Global $a1D[5] = [1, 2, 3, 4, 5] _ArrayDisplay($a1D) _ArrayClear($a1D) _ArrayDisplay($a1D) Func _ArrayClear(ByRef $aArray)     Local $iCols = UBound($aArray, 2)     Local $iDim = UBound($aArray, 0)     Local $iRows = UBound($aArray, 1)     If $iDim = 1 Then         Local $aArray1D[$iRows]         $aArray = $aArray1D     Else         Local $aArray2D[$iRows][$iCols]         $aArray = $aArray2D     EndIf EndFunc   ;==>_ArrayClear

UDF List:
Spoiler
Updated: 31/03/2015

#6 hezi

hezi

    Seeker

  • Active Members
  • 34 posts

Posted 09 January 2012 - 04:40 PM

thanks guinness!





Also tagged with one or more of these keywords: Array

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users