Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

Nimajneb H

Variable name memory allocation

This topic is 5466 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post

Link to post
Share on other sites
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.


Share this post

Link to post
Share on other sites
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[ i ] ; ).

If you can come back 3 years later and undersatnd your code, then you have little to worry about on naming your variables.

Hope this helps.


Don't follow me, I'm lost.

[edited by - Stevie56 on July 6, 2003 6:03:28 AM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!