Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Saving memory

Discussion in 'Scripting' started by XRenkoX, Dec 12, 2014.

  1. XRenkoX

    XRenkoX

    Joined:
    Nov 3, 2013
    Posts:
    14
    Okay I am loading all of my game data into an array. Now the question is should I have constant int indices labeled as CONST_PLAY_MAX_SPEED or should i just load the data into variables. I know if I use the const strategy I save memory but if I put them in variables it makes sense too.
     
  2. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    you're worried about one int variable? I wouldn't waste my time if i were you
     
    SunnyChow likes this.
  3. XRenkoX

    XRenkoX

    Joined:
    Nov 3, 2013
    Posts:
    14
    i am worried about a larger number such as 20, program clarity, and memory space for mobile development.
     
  4. Korno

    Korno

    Joined:
    Oct 26, 2014
    Posts:
    518
    Don't get carried away with such small optimizations until performance becomes an issue. Of course big optimizations should be done early on, but optimizing 20 ints? If you need to save 20 ints worth of memory, you have got some other major bottlenecks!
     
  5. cmcpasserby

    cmcpasserby

    Joined:
    Jul 18, 2014
    Posts:
    315
    Pre mature optimization is a big biggner mistake and a waste of time. If you got performance problems profile your game and figure out where the bottle neck is.
     
  6. Kirk Clawson

    Kirk Clawson

    Joined:
    Nov 4, 2014
    Posts:
    65
    Don't bother optimizing 20 item arrays-vs-variables. Don't even bother with 200, or 2000, or even 20,000.

    I wouldn't worry about optimizing access and storage of values like this until I got to about the 2 million mark. At that point, though you've likely got data structure issues that will need addressing before you worry about it.
     
  7. XRenkoX

    XRenkoX

    Joined:
    Nov 3, 2013
    Posts:
    14
    what about program clarity?
     
  8. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    937
    What happens to be the most logical solution. It isn't really possible to judge which option that is by the information you provided. If you want the int to be adjustable at runtime, be it via some option menu, or maybe you want to load it from a config file.