Skip to main content
gamedev.net
🔒 Locked

Variables and Memory Usage

Started by Big Boy Rees 2 replies 250+ views
Original Post
Big Boy Rees
Big Boy Rees
Hi, not sure if this is the right forum. :S Um, I was just trying to make a game engine today in VB 5.0, and decided I would make an array for 1 thousand in game characters, each having an inventory, skills, scripts.. etc. All up it came to somewhere between 30 and 50 variables per character, depending on what script gets assigned to them. What I was wondering.. is this way over the top in memory usage? I read in help that an integer only takes up 2 bytes. So does that mean if I wanted say a max off 40 mb of ram used on character information, 40 mb * 1024(kb) * 1024(b) is 41943040. Does that mean I have 41943040 bytes to use on characters? so, 41943040/1000 = 41943.04, so 41943 bytes per character? which is 10 thousand 4 byte variables...? Im not sure if that was complete gibberish or not now that I skim over it.. hehe My question is.. will 1 thousand lots of 30 variables (mainly integers, strings and longs) use heaps off ram?
yes, yes I am stupid.
JuNC
JuNC
Your integers and longs will almost certainly be using 4 bytes. Strings will depend on how long the string is (unless you can use fixed-length strings, I''m not sure about VB).

Lets see, 1000 * 30 * 4 = 120000, around 120k if they were all integers. Don''t know what you store in strings so I''ll estimate an average of 10 strings of 15chars per character (plus a bit for string object overhead)..

1000 * 10 * (15 + 8) = 230000, around 220k, so in total you are using under 400k for the total data space.

The moral: don''t worry about how much space your game logic state is going to take, the main place memory is taken up is with art assets (sound effects, sprites, textures, models).
Wildfire
Wildfire
Short answer: yes =)

If an int uses 4 bytes (In Windows it does) 1000 ints use 1000 * 4 bytes.

Actually I think your programm will even need more than that, not quite sure about how much overhead there is for managing the allocated memory and such...

If you're running on Win2k/XP try opening the task manager, and go to the 'processes' tab. There you can see how much memory each programm currently "consumes"

But as JuNC says... saving on variables won't help you all too much... (hi-res) textures are the real killers.

[edited by - Wildfire on December 14, 2002 8:28:58 AM]
How do I set my laser printer n stun? o
Big Boy Rees
Big Boy Rees
Hey Thanks

One less thing to worry about.
yes, yes I am stupid.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.