Sign in to follow this  
Followers 0

clearing Array


6 posts in this topic

Posted

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!

Share this post


Link to post
Share on other sites



Posted

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

Share this post


Link to post
Share on other sites

Posted

Cool !

thanks for quick reply!

Thanks Melba23

Share this post


Link to post
Share on other sites

Posted

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)

Share this post


Link to post
Share on other sites

Posted

Or another way is this >>

#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

Share this post


Link to post
Share on other sites

Posted

thanks guinness!

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0