Any under-the-hood differences between variable types?

  • I was wondering if variable types had any impact on performance in games just out of sheer curiosity. Like my friend told me in programming text variables are most intensive and then numeric and then boolean variables. Was just curious if this holds true for C2 and if there's anything else they impact besides that.

  • It is true for normal programming! booleans, integer, floating point, text... I am also curious about C2.

  • Well there is global, and then there are regular variables.

  • Well there is global, and then there are regular variables.

    That's not what they mean, turefalcon - in "proper" programming it is possible to set a variable type depending on projected usage - like int (only round numbers), float (numbers with decimals), string (for words and such) and also different subtypes (how big the number can get - up to 255, or up to 32767 or 2 billion something), signed or unsigned, etc. In olden times this had a big effect on the memory usage. I don't think it matters that much nowadays, but it would be neat to know for sure.

  • I don't think it matters that much nowadays, but it would be neat to know for sure.

    It does not. Nowadays developers don't have to pay that much attention to declaring the proper type of variables to save memory. You can save much more memory by cutting off the unnecessary transparent parts of the images your project uses.

  • I am pretty sure that all number variables are handled as floating point numbers. This can cause some strange things to happen if you're not ready for it. See here for some discussion on it.

  • Yeah, it is interesting, I remember when I read programming books about the importance to use proper variable because if you do not declare it as anything you will get the most wasteful one, oh the horrors! ;D

    but glerikud is right, now in comparison, there are so many other things that are more wasteful..

  • I am pretty sure that all number variables are handled as floating point numbers. This can cause some strange things to happen if you're not ready for it.

    That's true, but in these cases you can use the int() function to convert the number to an integer value.

  • That was back when computers would actually slow down while trying to do math.

    Putting your trash can back under the cupboard was important when your kitchen wasn't wide enough for two people, but it's a warehouse now. It will only make a difference to the neurotic. <img src="{SMILIES_PATH}/icon_e_wink.gif" alt=";-)" title="Wink">

    Ashley's Blog: Optimisation: don't waste your time

    https://www.scirra.com/blog/83/optimisa ... -your-time

  • Yeah, don't waste your time. Or, answer the question yourself! This question might have mattered in say 1990 when processors were around 25MHz so you might have noticed this sort of thing.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I think it's important to note that if you are targeting a game for mobile, ARM based processors have a much more difficult time processing floating point numbers then integers.

    It is not terribly important. This is only going to cause an issue with massive number crunching. Still, it's fascinating to know the differences and how processors handle numbers.

    You might want to know the difference for other things though. For instance, floating point numbers can technically be less accurate then integer based numbers. This is a big deal for heavy accounting software. It's better to convert any moneys to pennies (for American money), do the maths, and convert it back to dollars and change.

    If you venture into C++ or C land, it's important to know the differences. These languages treat memory handling far different then Java or Javascript.

    With all that said though, for the scope of Construct, and as Ashley has said, it doesn't matter really.

  • Well the other programmer who quit the project told me I HAD to make sure I got their types right and he used to be a professional programmer. I guess he's living in the past. I just was curious if it'd have an accumulative effect of specifying the wrong type for variables by the end of my game's production or not when I have like 10,000 variables. This is because I noticed he also did stuff like used for each loops wrong everywhere in the code that really impacted performance. So I was kinda doubting him but wanted to be 100% sure.

    For the sake of convenience though I will be sure their types are correctly set.

  • Well in the context of Construct 2, you have the overhead of the entire event engine, so worrying about variable types is very much like the analogy from the blog post of cleaning your car in the hopes it makes it faster. There are definitely more useful things to think about.

  • TLDR

    It depends on how dirty your car is.

  • Had I seen the new blog before answering this, I would have mentioned it. <img src="{SMILIES_PATH}/icon_e_wink.gif" alt=";-)" title="Wink">

    Mythbusters Dirty vs clean car was a surprising result. Golf ball effect. Dimples are better. <img src="{SMILIES_PATH}/icon_e_wink.gif" alt=";-)" title="Wink">

    http://www.discovery.com/tv-shows/mythb ... clean-car/

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)