Archived

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

Nimajneb H

Variable name memory allocation

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
Guest Anonymous Poster
Variables don''t have names in the compiled assembly. They''re just for your convenience in the IDE. So, no there is no advantage to shortening them, aside from saving space on your monitor. Give them the most descriptive names you can.

Share this post


Link to post
Share on other sites
Well, when the program is being compiled the compiler has to store variable names temporarily somewhere in memory, because it has to reference them, but I''m sure only as long as their scope. In terms of program performance it makes no difference though. Just keep your variable names informative and you won''t have to worry. If worse comes to worst, you can increase the amount of memory the compiler is allowed to use. It''s an option somewhere.

Share this post


Link to post
Share on other sites
quote:
Original post by Zipster
If worse comes to worst, you can increase the amount of memory the compiler is allowed to use.



If your variable names are sooo long the compiler needs more memory then you''ve got bigger things to worry about :D

but really the variable names a lost when you compile so it won''t affect anything ... just open up one of your apps in a hex editor try searching for them if you don''t blieve us!

Share this post


Link to post
Share on other sites
Remember that c is an old language. Function names like strcpy where useful before since they edited and compiled files on system having less than 0.5MB RAM. Nowadays, some people still claim that using short names is good. The worse excuse I read was that "If you keep the names short then the chance for typos are smaller". It''s so much easier to spell to strcpy than stringcopy? The lexicator will use some more memory, but if you think that''s a problem you might want to skip putting comments in your code as well.

Share this post


Link to post
Share on other sites