Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / How much space do integers take?

Author
Message
Mark532011
8
Years of Service
User Offline
Joined: 27th Jun 2016
Playing: X-Com, WOW-Legion
Posted: 27th Jul 2016 18:15
I'm looking to make multiple maps (say 20), probably 100x100 in size with a few different basic values in each tile (i.e. ground, tree, rock,etc.)

I originally thought a 100x100 integer array but I suspect integers are 4 bytes in size, leading to 40k per map. Usually characters are 1 byte in size, making for much smaller memory required so I could go with a string array instead.

However I don't know AppGameKit and how it handles things. Is there a sneaky way for something like this (like writing pixel values onto an invisible sprite or something) or are the numbers just too small to worry about (20 maps of 40k = 800k)

Mark
JLMoondog
Moderator
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 27th Jul 2016 21:18
I don't know the behind the scenes mechanics of AppGameKit, but I've created several games that use many variable arrays at a time. You won't see any slow down, I've yet to see any type of slow down or lag so far based on my experience. For example, my current project has 12 variable arrays, the largest being the enemy boss array that has over 25 type variables within the array itself, with over 100 procedural-generated variations saved in the array. No issues.

Have fun with your project and good luck!
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 27th Jul 2016 22:05
Quote: "Usually characters are 1 byte in size, making for much smaller memory required so I could go with a string array instead."


Characters are 2 bytes.

Using integers, you can specify what is in each cell. For example:

1 = grass
2 = tree
4 = rock
8 = gold

Therefore a grassy cell with a tree and gold has a value of:

1 + 2 + 8 = 11

A little bit of binary mathematics gets the contents of each cell.With an integer you can have up to 32 different elements in a cell using this method.

800Kb is tiny, space is not an issue for you.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Mark532011
8
Years of Service
User Offline
Joined: 27th Jun 2016
Playing: X-Com, WOW-Legion
Posted: 28th Jul 2016 00:26
Cool, thanks!

Login to post a reply

Server time is: 2024-11-21 20:23:09
Your offset time is: 2024-11-21 20:23:09