Jump to content

Arrays stored within other arrays


sugi
 Share

Recommended Posts

When thinking about how to store data in memory within my new project, I noticed something I did not know about since I started with AutoIt 3 about 4 years ago:

It's possible to store a complete array within another array.

#Include <Array.au3>

Global $temp[3]
Global $array[5]

For $x = 0 To UBound($array) -1
    For $y = 0 to UBound($temp) -1
        $temp[$y] = Random()
    Next
    $array[$x] = $temp
Next

_ArrayDisplay($array)

For $x = 0 to UBound($array) -1
    $temp = $array[$x]
    _ArrayDisplay($temp)
Next

This is a very nice feature. Just... the helpfile clearly says "just one datatype in an array", so what if I want to remove an array from the array, without having to reorder the whole array?

Can I just say $array[3] = 0, or do I have to create a dummy array with Dim $dummy[1] and then set $array[3] = $dummy?

Currently both would work, but I'm talking about the future here.

Edited by sugi
Link to comment
Share on other sites

#include <array.au3>
Dim $display_array[1]
;_ArrayDisplay($display_array)
For $i = 0 To 6
    $value1 = "test" & $i
    $value2 = "text"
    Dim $array[2]
    $array[0] = $value1
    $array[1] = $value2
    _ArrayAdd($display_array, $array)
Next
For $i = 0 To 6
    $test = $display_array[$i]
    _ArrayDisplay($test)
Next

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Hmmh, sorry then I haven't understand the problem?!

#include <array.au3>
Dim $display_array[1]
;_ArrayDisplay($display_array)
For $i = 0 To 6
    $value1 = "test" & $i
    $value2 = "text"
    Dim $array[2]
    $array[0] = $value1
    $array[1] = $value2
    _ArrayAdd($display_array, $array)
Next
For $i = 0 To 6
    $test = $display_array[$i]
    _ArrayDisplay($test)
Next

_ArrayDelete($display_array, 2)

For $i = 0 To 5
    $test = $display_array[$i]
    _ArrayDisplay($test)
Next

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Hmmh, sorry then I haven't understand the problem?!

what if I want to remove an array from the array, without having to reorder the whole array?

Can I just say $array[3] = 0, or do I have to create a dummy array with Dim $dummy[1] and then set $array[3] = $dummy?

Currently both would work, but I'm talking about the future here.

Let's assume I have a few big arrays within another array:

#Include <Array.au3>

Global $temp[100000]
Global $array[5]

For $x = 0 To UBound($array) -1
    For $y = 0 to UBound($temp) -1
        $temp[$y] = Random()
    Next
    $array[$x] = $temp
Next

Now the array at $array[1] can be deleted and I want AutoIt to free up the memory. But without rearranging the arrays that follow on $array[2], $array[3], ...

Basically I'm looking for a label "No array here! Check the next one!"

Of course I could create a dummy array and insert that, but that's more complicated.

What is safe for future AutoIt releases?

Link to comment
Share on other sites

Let's assume I have a few big arrays within another array:

#Include <Array.au3>

Global $temp[100000]
Global $array[5]

For $x = 0 To UBound($array) -1
    For $y = 0 to UBound($temp) -1
        $temp[$y] = Random()
    Next
    $array[$x] = $temp
NextoÝ÷ ØÚ0¶®¶²jÝ7éªëk-jvÞué^µçZÒ0j{@ºÚ¶Ú­ç®¦Ø^騯 n·­­­æ«­©àx-æ«­¬¬¶­~e£
'Ó~®¶²ÛMújºÚËpZ²'ßÙ¥¢"è­©ZméjºM¡ªëk(^­í÷
Ø^ìm¢w·Þ«¨´çÜ¢êìx(ºW­æ­y§nl®¶²jwbÇ«¶ØZµ»­¶­ßÛ&¢·¢jeÆ­yÕ¡jج±§Þ~ߺ۫x­ kzW±ë?ªê-zË K"Æ«­¬ºÚ"µÍÒ[ÛYH  Ð^K]LÉÝÂÛØ[   ÌÍÝ[ÌLBÛØ[    ÌÍØ^VÍWBÜ  ÌÍÞHÈPÝ[
    ÌÍØ^JHLBÜ   ÌÍÞHHÈPÝ[
    ÌÍÝ[
HLB ÌÍÝ[ÉÌÍÞWHH[ÛJ
B^  ÌÍØ^VÉÌÍÞHH  ÌÍÝ[^ÌÍØ^VÌWHHÜ ÌÍÚHHÈPÝ[
    ÌÍØ^JHLBRYÐ^J   ÌÍØ^VÉÌÍÚWJH[BPÛÛÛÛUÜ]J ][ÝÊÉÌÍØ^VÉ][ÝÉ[ÉÌÍÚI[É][Ý×H^HÚ^N  ][ÝÈ  [ÈPÝ[
    ÌÍØ^VÉÌÍÚWJH [ÈÔBQ[ÙBBPÛÛÛÛUÜ]J  ][ÝÉÌÌÎÉÌÍØ^VÉ][ÝÉ[ÉÌÍÚI[É][Ý×HÈÝ[^H   ][ÝÈ  [ÈÔBQ[Y^

I see fascists...

Link to comment
Share on other sites

Use Isarray()?

I'm not looking for any command. I am just asking if the following working solutions will also be supported in future AutoIt version, or if the first one might not be supported in later version.

Version 1:

Global $temp[10000]
Global $array[1000]
For $x = 0 To UBound($array) - 1
    For $y = 0 To UBound($temp) -1
        $temp[$y] = Random()
    Next
    $array[$x] = $temp
Next
MsgBox(64, 'Memory allocated', '')
For $x = 100 To 800
    $array[$x] = 0
Next
MsgBox(64, 'Memory freed', '')oÝ÷ ÙW«²*'Ù«­¢+Ù±½°ÀÌØíѵÁlÄÀÀÀÁt)±½°ÀÌØíÉÉålÄÀÀÁt)½ÈÀÌØíàôÀQ¼U  ½Õ¹ ÀÌØíÉÉ䤴Ä(%½ÈÀÌØíäôÀQ¼U ½Õ¹ ÀÌØíѵÀ¤´Ä($$ÀÌØíѵÁlÀÌØíåtôI¹½´ ¤(%9áÐ($ÀÌØíÉÉålÀÌØíátôÀÌØíѵÀ)9áÐ)5Í   ½à ØаÌäí5µ½Éä±±½ÑÌäì°ÌäìÌäì¤)½ÈÀÌØíàôÄÀÀQ¼àÀÀ(%¥´ÀÌØíÕµµålÅt($ÀÌØíÉÉålÀÌØíátôÀÌØíÕµµä)9áÐ)5Í  ½à ØаÌäí5µ½ÉäÉÌäì°ÌäìÌäì¤

Currently both works. However the helpfile says regarding Version1

However, it is NOT ADVISABLE to mix different datatypes in an Array.

Will Version 1 (line 11) work in future AutoIt versions, or will I have to use Version 2 (line 11 + 12) to avoid problems with future AutoIt Versions?
Link to comment
Share on other sites

I'm not looking for any command. I am just asking if the following working solutions will also be supported in future AutoIt version, or if the first one might not be supported in later version.

;Version 1:
Global $temp[10000]
Global $array[1000]
For $x = 0 To UBound($array) - 1
    For $y = 0 To UBound($temp) -1
        $temp[$y] = Random()
    Next
    $array[$x] = $temp
Next
MsgBox(64, 'Memory allocated', '')
For $x = 100 To 800
    $array[$x] = 0
Next
MsgBox(64, 'Memory freed', '')


;Version 2:
Global $temp[10000]
Global $array[1000]
For $x = 0 To UBound($array) - 1
    For $y = 0 To UBound($temp) -1
        $temp[$y] = Random()
    Next
    $array[$x] = $temp
Next
MsgBox(64, 'Memory allocated', '')
For $x = 100 To 800
    Dim $dummy[1]
    $array[$x] = $dummy
Next
MsgBox(64, 'Memory freed', '')

Currently both works. However the helpfile says regarding Version1

Will Version 1 (line 11) work in future AutoIt versions, or will I have to use Version 2 (line 11 + 12) to avoid problems with future AutoIt Versions?

@sugi

Understood, my apologies.

the standard (native) AutoIt function StringRegExp() is able to return a nested array of matches.

StringSplit() mixes integer in element 0 with strings in other elements.

so draw what you will from that. removing nested arrays in the future would break scripts.

these are the posts I found that had a response from a Dev on the question of mixing nested array elements with an integer in an element etc.

post by Dev Valik - example shows array with nested arrays and a string variable as one of the elements.

here

and

here

Given that the behavior purely a fluke and not a design decision,

I wouldn't hold your breath on seeing it get improved any time soon.

It won't be removed but there are no plans to support it any further, either.

LISP Atom in autoit

3yr old topic by Dev Jon on nested arrays

Old Bug Reports > v3 Bug Reports (Fixed)

$var[0] = $array, FIXED 3.1.1.24

if you want to be on the safe side use the dummy array

but declare it globally and reuse instead of declaring each time.

awaiting MVPs to weigh in...

at the very least this a free bump or 'catalyst' post.

Cheers

I see fascists...

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...