Does the Length of Variables Affect Memory?

I have been wondering this question for a very long time and have been unable to find a good answer, does the length of variables affect memory?

And another question, what type of variable is best to use?

snake_case = true
PascalCase = true
camelCase = true
svar = true --Short Variable
  • Snake Case
  • Pascal Case
  • Camel Case
  • Short Variable

0 voters

2 Likes

i would assume yes, however i think it scales on number of characters ONLY.

Assuming you’re using basic letters and underscores, it wouldn’t really take up much more memory. ASCII characters should only take up 8 bits (1 byte). When your code gets run, the compiler won’t really care about the name of your variables. Instead it will work with memory addresses and references.

2 Likes

No. Variable names get lost when compiled which is the reason why decompilers can’t get the original variable names.

2 Likes

In their precompiled states a script with longer variable names will consume more memory than a script with shorter variable names. The difference would be negligible though.

2 Likes

Adding onto the good answers, it’s important to remember that some space is always used to store the type of a value (size of a long long as far as I know, usually 8 bytes).

About naming conventions, I use snake case for table keys and functions. I shorten identifiers when they are understandable to me.

Just realized you were talking about identifiers and not values, so the first paragraph is irrelevant.