Jump to content

Recommended Posts

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!

  • Moderators
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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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:

  Reveal hidden contents

 

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)

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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
×
×
  • Create New...