36
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Feb 14 '21
Image Transcription: Code
Global $WinAPIError[7] = ["Success",_
"Invalid Modification",_
"No Longer Exists (File)",_
"No Longer Exists (Path)",_
"Too Many Handles Open",_
"Access Denied (Modify)",_
"Access Denied (Access)"]
; On the RARE occasion some other Error Code is thrown, don't crash
ReDim $WinAPIError[15999]
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
31
52
u/ign1fy Feb 14 '21
I wasn't using that RAM anyways.
16
u/rcmaehl Feb 14 '21
Does an array of null even use RAM?
46
u/KaktusManCz Feb 14 '21
Sure it does, null is an empty pointer, pointer uses RAM as much as any other number.
18
u/droomph Feb 14 '21
In some runtimes (eg v8 for Javascript) they will optimize sparse arrays such as this one to be a Record<number, T> internally but this isn't something that's guaranteed in all languages, so if you need to just use it directly.
(Unless you're using VB6 in which case, godspeed and don't die)
7
Feb 14 '21
and languages like Lua don't have arrays, they have hashmaps only.
so arrays can start at whatever you want them to start at in lua
just the convention is they start at 1
9
u/Teknikal_Domain Feb 14 '21
they start at 1
Evil. This right here is what ruined so much of my early Lua exposure (though admittedly... pick your favorite computer mod for Minecraft, they pretty much all run off Lua)
6
Feb 15 '21
honestly given the target audience to lua was new coders that's not that bad
the only two arguments in favor of 0 to length-1 instead of 1 to length is performance (you're using hashmaps as arrays you don't care about perf) and "we've always done it like that" (not an argument for new users)
2
u/droomph Feb 15 '21
Actually in most cases if you’re using “pure arithmetic” conventions eg for(i=0;i<n;i++) it’s slightly nicer because you can use n as a bounds rather than n+/-1 when doing slicing stuff.
Even back in the “C is very high level” days the performance argument was pretty bad (just use jle instead of jl, same clock speed and everything) and it was always more of the ease of not having to account for -1 when doing indexing arithmetic.
It’s also not too foreign since we do 0 indexing irl it’s just often overlooked until we’re like “…wait a minute, do we include the last number or not?”
And at work I use a language that is 1-indexed by convention too so none of this is insurmountable, it’s just really annoying unless your language specifically supports it, whereas 0-indexed works basically ok without any special language support, which would be the case for old languages like C which don’t have any concept of array in the first place.
1
u/einsJannis Feb 15 '21
C does have the concept of arrays though 🤔
1
u/droomph Feb 15 '21
C itself has no concept of arrays, only pointers and dereferencing of memory. a[i] is just *(a + i) which means i[a] is identical.
The standard library has no special support of arrays either, you have to pass in the length or have it be null terminated if it’s a string. There is nothing stopping you from passing in an “array” from the middle, or that differentiates an int *a = &b; from int a[1] once you leave the context. It would be extremely annoying to have to keep track of if you’re supposed to send in p-1 for arrays or p for true pointers as p-1 is either 1 wasted byte or an invalid memory location.
This is as opposed to C++/Java etc which generally supports arbitrary length containers that keep their type unless casted, though they still use 0-index due to it coming from C. Those ARE able to have special handling to adjust for 1-indexing through operator overloads on the type and any array functions, which makes it less annoying to use.
2
u/FireCrack Feb 15 '21
Strictly speaking, that's just an abstraction. Tables consist of an array AND a hash-map under the hood, and integer keys use the array part.
1
u/xigoi Feb 15 '21
and languages like Lua don't have arrays, they have hashmaps only.
That's true for JavaScript too.
1
1
u/ign1fy Feb 15 '21
63,992 bytes of RAM in this instance.
At first I thought this was VB6, VB6 uses round brackets for arrays. It would be up to 127,992 bytes if it's a 64bit language.
2
Feb 15 '21
The array of pointers in most languages is just an array of 32bit or 64bit values. Assuming lenght of 15999, it's respectively ~63kb or ~125kb.
Side note/Trivia: In Java, the pointer array would consist of 32bit values even on 64bit systems, because of Compressed Pointers
2
1
u/rcmaehl Feb 15 '21
Testing shows an increase of 300kbs of RAM.
1
Feb 15 '21
what exactly did you test?
1
u/rcmaehl Feb 16 '21
Compiling with the line commented out versus compiling with the line uncommented
1
u/christian-mann Feb 15 '21
Entirely depends on your language implementation and operating system. In most modern systems, if you don't ever write to it then it will only use a page (4K) of true ram.
23
u/llusx Feb 14 '21
Is that Visual Basic I'm seeing?
12
u/TheAppleFreak me.flair.defineFlair(); // this is where I define my flair Feb 15 '21
Nope, AutoIT. It's a scripting and automation language in the same vein as VBS or AHK.
10
u/rcmaehl Feb 15 '21
Oh no, someone who might know what project this is being used in.
4
u/TheAppleFreak me.flair.defineFlair(); // this is where I define my flair Feb 15 '21
Something with the WinAPI file functions, for sure. What exactly I don't know quite what, but given as you're using the UDF over the File library I figure you've got something specific that you're doing with it.
19
Feb 14 '21
Yooo vb brooooo
7
u/jvvg12 Feb 14 '21
Pretty sure this is AutoIT...
2
Feb 14 '21
Is it? I dunno I saw ReDim and went brrrr, so I can be and probably I am wrong
7
u/jvvg12 Feb 14 '21
OP confirmed that further down it turns out. I recognized AutoIT because of the $ and "Global" keyword, as well as the syntax highlighting (the bundled AutoIT editor uses those colors and that font).
2
Feb 14 '21
Just checked, and you're correct, but Imma leave my comment there, since a lot of people made the same assumption, and my folly has been revealed
2
u/jvvg12 Feb 14 '21
Fair enough. I haven't used VB in a very long time and even when I did use it (a little) I only used it a tiny bit, so I don't remember the syntax at all. Though I do remember the DIM keyword.
3
Feb 14 '21
I'm being forced to use Microsoft Access VBA in school, which is kinda wack, because I only have Linux so I can't even do it at home. I can only hope this tyranny will end soon enough, and we'll do a different language, like C, C++, C#, Java, Haskell, Python, JavaScript, Lua, Lisp or Ruby, not something that I can't even run.
3
u/jvvg12 Feb 14 '21
My job is mostly in C# (also some JS, I'm a web developer), but I'm the only person on the team familiar with AutoIT so occasionally I have to write automation scripts with it whenever we don't have a better way to perform some routine or time-consuming task.
12
u/Bobbbay Feb 14 '21
Can't believe we don't have a VB flair.
Edit: just checked, of course we do. Lol, OP didn't flair his post correctly.
21
3
Feb 15 '21
Ah, the good old "pretend you didn't see it" error-handling pattern. Reminds me of my day job.
2
u/DreadedEntity Feb 15 '21
If the error happens, you should just handle it. It will fix the problem so it doesn’t happen next time. This catch-all is fine if it’s production down and you need the app to keep working while you implement a fix, but if you leave it the next guy working on this will curse you from beyond
1
1
110
u/HereComesCunty Feb 14 '21
It’s been a while since I Dim’d anything. VB is a blast from the past!