Jump to content

About the arrays


Recommended Posts

Hey there,

First of all: I've read nearly every single thread already existing about the question I am about to ask, but I don't feel satisfied, so here I am :)

I'm using AutoIt for quite a long time now, and never really needed to use this kind of feature ... until now.

Well, that's quite something usual in other langages, and as far as i know there's not a conveniant way to do it in AutoIt, but maybe I lack some knowledge.

So long story short :

Is there a way to compare AutoIt array by reference ?

local $a = [0]
local $c = [0]
local $b = $a

cmp($a,$b) = True
cmp($a,$c) = False

And furthermore accessing array by ref (something like that)

local $a = [0]
local $b = [$a]

$b[0][0] = 5 ; implies $a[0] = 5

Of course, as mentionned in other threads, AutoIt doesn't handle array as a usual C type array and lead to the non-sense of a ptr in some cases (that I don't really know / understand)

But I used some kind of stuff like that in AutoIt before, and I, sadly, don't remember exactly how I did it :/

And well, yes, I could use a dllstruct to get a direct pointer to an array

local $struct = dllstructcreate('byte[...]')
local $ptr = dllstructgetptr($struct)

But as I need to feel my array with other data, i hope i could dodge a completly dllstruct'ed code that will force me to add ptrs in the structs.

So maybe there's no way to do it (as already said on the forum: "AutoIt is for automation scripts, if you need ptrs use an other langage", but well comparing arrays by ref is not something abnormal for a "scripting langage", it has MAAAAANNNNY uses)

Thanks, Cheers,

Clean o/

Link to comment
Share on other sites

AutoIt is a BASIC-like scripting language that is much more related to e.g. VBScript than it is to low level languages such as C.

In many scripting languages including both AutoIt and VBScript, arrays are implemented as safearrays of variants. Ie. a safearray where each array element consists of a variant.

These are array manipulation functions that are useful for safearrays. As you can see, there are no direct functions to compare safearrays.

Accessing AutoIt Variables demonstrates how to convert an AutoIt array to a safearray and vice versa based on techniques that utilize internal AutoIt COM conversions. But the code isn't completely trivial.

The direct answers to your questions are:

 

13 hours ago, 636C65616E said:

Is there a way to compare AutoIt array by reference ?

No, there isn't. And there is also no safearray API function for the purpose.

 

13 hours ago, 636C65616E said:

And furthermore accessing array by ref

An AutoIt array cannot be directly accessed through a reference pointer, but the corresponding safearray and associated array elements can be accessed through pointers.

 

13 hours ago, 636C65616E said:

And well, yes, I could use a dllstruct to get a direct pointer to an array

Through a DllStruct you can obtain a pointer to a C-type array. But a C-type array is not the same as a true AutoIt array.

 

13 hours ago, 636C65616E said:

but well comparing arrays by ref is not something abnormal for a "scripting langage"

Do you have an example of a scripting language where you can compare arrays through reference pointers?

Link to comment
Share on other sites

heyhey,

thanks for the answer and clarification about the safe array stuff, i never dived into the memory management of AutoIt, but i shoud do it :)

24 minutes ago, LarsJ said:

Do you have an example of a scripting language where you can compare arrays through reference pointers?

To be honnest, i'm not really into this kind of programmation, so I don't have so much example, but i guess there's some reference to data in R (i consider R as a scripting language)

I can provide a concrete example for the need of references, implementing a RB-Tree in AutoIt, it is usefull, doable without the references etc, but using references could be a way easier way to do it. (this example of RB-Tree is why i came here in first instance, but this is not an end in itself)

In a more general matter, using reference is useful for a lot of data structures, and those are not really related to the language objective or specifications (that's why I call it "not abnormal")

Anyway the hammer fell: if the way the vm/interpreter handles memory doesn't allow this kind of stuff, there's no way to do it, but it also doesn't mean it shouldn't change in the future haha, joking, but could be useful.

PS: i guess i have an example for you, ones can argue LUA is a scripting language, and there's references in it, they are not that straight forward, but they exist or kinda exist. If you can't affort the pure reference, using something similar than the global table of a LUA env with some (maybe hidden) hashed keys/references can do the job, and everyone would be happy hehe.

I'm not there for language improvement request, but beeing able to use a function returning a unique hash/ptr/ref/whateveryouwannacallit for a given array (as u mentionned you can access safearrays through pointers) could do the job, the exact meaning of it or the way it is generated doesn't matter ... (and anyway you can push arguments by reference in the functions, soooo ... i'm starting to be quite confused haha) as far as i understand the problem now it is not about the capability of the language but the choice to not deploy it by the dev team, but maybe i'm still wrong ^^

 

Link to comment
Share on other sites

2 hours ago, 636C65616E said:

as far as i understand the problem now it is not about the capability of the language but the choice to not deploy it by the dev team

... I don't know much about other languages but the question is why choosing AutoIt. Who are the dev team and where you fit in the dev team. What needs to be achieved for AutoIt to be a good fit.
Thanks for your time and welcome to the forum @clean

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

There's plenty of reasons why I use AutoIt, and I will continue to do so, to call 2 of them: easy GUI and fast/easy OS interaction

The language is prety well designed for what I expect from it, and beside this reference consideration, I don't think it needs other major features (well sometimes OOP could be a plus, but ... meeeh).

Anyway I'm not here to discuss and argue about that :3

Quote

Thanks for your time and welcome to the forum @clean

Thanks :D

The question have been answered.

But on the other side: why is it not an existing feature ? I agree and understand why it is not doable in first place, but it should be, like from the VM/interpretor pov I guess there's no downside to add it to the specs (again: maybe I'm wrong and, therefore, a quick explanation is always welcome).

 

Link to comment
Share on other sites

I knew some pascal to code TSRs ( terminate and stay resident ) back in the days of DOS. Windows came along and by then I found AutoIt and did not give it a second thought. This thing is awesome. I read in the forums about the magic of other languages but as you well put it, "meeeh". I know that if you know ASM, you can run it from within AutoIt, etc. .
The OOP concept/idea may have made little sense at the time of coding the bases of a stub that would interpret commands to automate window clicking and what not ( that in it self was the aim of this language ). I'm glad that it does as much as it does, given the original purpose. You should compare this v3 to the old v2 syntax.
I'm not a programmer, I'm like an I.T. guy who can make GUIs and SQLite stuff. That's pretty much it for me. Pointers are confusing as I don't know if is music or dogs :D 
There is a ticketing system to work on bugs and feature requests. You can look around and get a better idea of what could be implemented and what is purposely denied.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

I've beat around this bush plenty of times myself.  You hit the mark when you mentioned about having dllstructs all over the place to get pointer type functionality.  That's probably the path of least resistance bc its well documented and offers some type of preexisting structure for data going in and out.  There are other options tho.  One being allocating memory directly using _MemVirtualAlloc() (an even simplier way is to use _WinAPI_CreateBuffer() )  so you would be getting a raw block of memory and you can literally iterate though it using _WinApi_ReadProcessMemory() and the alternative write process memory.  If this is the route you decided to take you'r life will be far simplier by keeping these "arrays" as one data type.  You aren't going to want to mix and match types bc it would be impossible to keep track of the size of the elements etc. 

The only other thing I can really add to this is that it makes alot of sense to save the memory pointers of the elements in a raw block of memory in an actual array for direct access.  Bc after all whats the point of using pointers if you're going to iterate through the entire block everytime you need to do something.  I suppose it wouldn't be that difficult doing pointer math on the initial pointer created but it would simplify things to have an array of pointers.  This is a slippery slope bc once you go this path all you end up with is pointers and then you really start wondering why you're going though all this when c++ is the same rigmarole.  If you understand the actual point of pointers and the math and pissing with raw memory it really does defeat the purpose of why you're here in the first place and that's simplicity.     I will say tho that the c languages are amazing.

Link to comment
Share on other sites

  • Moderators

Hiya - and apologies in advance for the thread drift.

Quote

code TSRs ( terminate and stay resident ) back in the days of DOS

That brings back a lot of memories. I wrote loads of these in ASM back in the day to "improve" my DOS experience: different error sounds; all sorts of editable keyboard shortcuts; a new editable command console with scrolling of previous commands; intercepting and amending printer commands to get better effects from the limited repertoire available; and even a batch utility suite with expanding message boxes, interactive menus, text in various colours, sounds, etc. It was a lot of fun!

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I will not go more in depth about that, but well ye I have some knowledge about real memory management, so yes of course i can do it this way in AutoIt, but i will not because it is not worth the time and performance.

I saw there are some COM objects for data structures (tbh i don't understand wth it exists, I mean that's not the purpose of COM, but well) like 'scripting.dictionary', so i will check a bit more the COM objects.

thanks 0/

Link to comment
Share on other sites

On 1/17/2021 at 3:37 PM, 636C65616E said:

Is there a way to compare AutoIt array by reference ?

local $a = [0]
local $c = [0]
local $b = $a

cmp($a,$b) = True
cmp($a,$c) = False

A patch has been sent by the devs for approval.  If accepted, comparing $b = $a will return True because memory address would be the same.

But comparing $c = $a will return False as it would imply to compare internal values of the array which would take too much time.

And the use of == for any comparaison involving arrays will return False.

Edited by Nine
Link to comment
Share on other sites

 

8 minutes ago, Nine said:

A patch has been sent by the devs for approval.  If accepted, comparing $b = $a will return True because memory address would be the same.

But comparing $c = $a will return False as it would imply to compare internal values of the array which would take too much time.

And the use of == for any comparaison involving arrays will return False.

Geez hell must be freezing over.  Im not sure how that's possible bc autoit doesn't use memory addresses, it only using vagrant chafed arrays or something

Link to comment
Share on other sites

Link to comment
Share on other sites

16 minutes ago, markyrocks said:

Geez hell must be freezing over.  Im not sure how that's possible bc autoit doesn't use memory addresses, it only using vagrant chafed arrays or something

well ... whatever the vm/interpretor does ... it stands in the memory in the end, so it has an address ^^"

and furthermore the vm/interpretor should use a reference based architecture to handle byref calls and some other stuff

but why i'm suprised is that in nearly every single thread about this topic, devs have always stated that it will not be a feature

Edited by 636C65616E
Link to comment
Share on other sites

2 hours ago, Nine said:

What ?

Do you mean that devs don't know what they are doing ?  But you do ? ;)

Are you trying to claim that I don't know what I'm doing? I wouldn't get too cocky sport.  Being an autoit superstar is like being the fastest guy in a one legged race.  

Link to comment
Share on other sites

  • Moderators

Just a quiet word in those ears that need to hear - keep it polite please.

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

17 hours ago, Nine said:

A patch has been sent by the devs for approval.  If accepted, comparing $b = $a will return True because memory address would be the same.

So do you think $a and $b have the same memory address at the end of this script?

Local $a = [0]
Local $b = [0]

Local $a = $b

$b[0]=1
$a[0]=2

ConsoleWrite($a[0] &" does not equal "& $b[0])

 or does it change when the element is modified, ala like in function calls?

 

Code hard, but don’t hard code...

Link to comment
Share on other sites

6 hours ago, JockoDundee said:

So do you think $a and $b have the same memory address at the end of this script?

Nope.  Should be false as new memory address is assign to the array.

Link to comment
Share on other sites

5 minutes ago, 636C65616E said:

well,$a and $b have different memory address but their values (referencing an array) should be the same

Not sure I understand that statement.  As soon as they do not share the exact same memory space they will become unequals whatever their values (contents) are...

For example :

#include <Constants.au3>

Local $a = [0]
Local $b = [0]
MsgBox ($MB_SYSTEMMODAL,"1",$a = $b) ; result False


Local $a = $b
MsgBox ($MB_SYSTEMMODAL,"2",$a = $b) ; result True

$b[0]=1
$a[0]=1
MsgBox ($MB_SYSTEMMODAL,"3",$a = $b) ; result False

$a = $b
MsgBox ($MB_SYSTEMMODAL,"4",$a = $b) ; result True

 

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...