Forum Moderators: open
For example, I've seen some research showing that when you Dim your variables, it creates a spot in memory for them, and provides an ordinal reference to the compiler -- creating faster code execution.
Can anyone dive a little deeper into this, possibly providing a more thorough explanation? I'm mostly looking for descriptions how the variables are stored into memory/ordinal references/faster execution.
msdn [msdn.microsoft.com]
I'll do some more digging.
Doesn't a variable that isn't of an explicit type get stuffed onto the heap as an object?
i = 10 <-- unknown so i would actually contain reference to a location on the heap where the value exists.
dim i
i = cint(10) <-- known value type that sits on the stack
the scripting run time references undeclared variables by name, every time they are used. Declared variables, on the other hand, are assigned an ordinal, either at compile time or run time. Subsequently, declared variables are referenced by this ordinal. Since Option Explicit forces variable declaration, it insures that all variables are declared and thus will be accessed quickly
[msdn.microsoft.com...]