- Home /
Which is the best way to make a 2D grid?
I have made a grid with a nested loop and it works fine. But, until now, I only needed 1 row and 30 columns of vector2's in my array. Now I need to have 4 rows and 30 columns, which will make a total of 120 vector2's. Correct me if I'm wrong, but I think this will be a lot of memory waisted, especially since this game is targeted for smartphones.. So, I was wondering if it is better for me to make 1 grid of 1 row and 30 columns (ARRAY 1) and another grid of 4 rows and 1 column (ARRAY 2), which is just 34 vector2's, and just find my location by matching the y location in ARRAY 2 to the x location in ARRAY 1?
Answer by robertbu · May 20, 2013 at 12:09 AM
I think you are trying to optimize in the wrong place. Vector2s are 8 bytes, so you are talking about 4 30 8 = 960 bytes...not even 1K (plus the overhead of the array itself). There is perhaps some additional memory used depending on how the memory manager is implemented, but still very small. This is minuscule compared to the amount of memory used by images. A single, uncompressed image the size of the screen for a lower res smart phones will take 2000 times as much memory.