Variable name memory allocation
Greetings and salutations!
I most humbly ask the advice of gamedev members on this topic...
Do variables (name, not type) have differing amounts of memory allocated to their storage depending on the length of the string naming them?
Many programming books suggest that tersely named variables adversely affect debugging/maintanence efforts due their difficulty for a human operator to follow. For example, if you want to store the number of people in a map at once, you might have an array:
...
{
int p[33] ; //number of people present on screen
...
}
The variable, p, is abstractly named.
Now lets say you want to store the number of photon cannons on screen:
...
{
int ph[11]; //number of active photon cannons present in map
....
}
You could keep on defining variables in this manner, their names are terse. But after many, many have been declared, you may lose track of what value each variable holds. You could try it this way:
...
{
int people[33];
...
}
The same for the other variables
...
{
int photon_cannons[11];
...
}
So, the crux of my question is; Are there any advantages (memory wise) to giving variables the shortest name possible?
Cheers! Benny
Absolutely not. When the compiler compiles your program(hah, it sounds funny , it really doesn''t care about the variable name. It stores an address to it, and that''s it. So no, there is no advantage whatsoever of using shorter variable names(except maybe the typing speed and shorter source code .
--------
Leave all your expectations behind, or
they''ll pull you down on your way to the top.
-Ivan
--------
Leave all your expectations behind, or
they''ll pull you down on your way to the top.
-Ivan
In general (and there are exceptions especially among compiler/interpreters) the length of the identifier has no effect upon a variable's location or storage requirements.
For example an integer will take up the same space whatever you call it or however long the name is.
Stated crudely the name is only used by the compiler, it is stored in a symbol table with the address, and any references to the symbol by name in your source are replaced by the address in the executable.
Most advice is to use meaningful names (and currently with an indication of the type of variable... thus sMyString, iMyInt, fMyFloat etc) and the size of the symbol table will usually not cause any concern.
I certainly wouldn't use short names for important data or arrays. I tend to only use single letter names for local counters (as in For int t = 0 etc ) or array indices (as in Thisperson = people ; ).<br><br>If you can come back 3 years later and undersatnd your code, then you have little to worry about on naming your variables.<br><br>Hope this helps.<br><br><br><br> <br><br>Stevie<br><br>Don't follow me, I'm lost. <br><br><SPAN CLASS=editedby>[edited by - Stevie56 on July 6, 2003 6:03:28 AM]</SPAN>
For example an integer will take up the same space whatever you call it or however long the name is.
Stated crudely the name is only used by the compiler, it is stored in a symbol table with the address, and any references to the symbol by name in your source are replaced by the address in the executable.
Most advice is to use meaningful names (and currently with an indication of the type of variable... thus sMyString, iMyInt, fMyFloat etc) and the size of the symbol table will usually not cause any concern.
I certainly wouldn't use short names for important data or arrays. I tend to only use single letter names for local counters (as in For int t = 0 etc ) or array indices (as in Thisperson = people ; ).<br><br>If you can come back 3 years later and undersatnd your code, then you have little to worry about on naming your variables.<br><br>Hope this helps.<br><br><br><br> <br><br>Stevie<br><br>Don't follow me, I'm lost. <br><br><SPAN CLASS=editedby>[edited by - Stevie56 on July 6, 2003 6:03:28 AM]</SPAN>
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement