GMS 2 DS List vs DS grid with embedded arrays

Flashpants

Member
Hello all

Our game is based off of a 120x64 grid and we want to hold multiple variables of information for each grid square (what room type it is, what's on it etc). The information in the variables will have to be accessed every few seconds by 50-100 different objects, so needs to be as fast as possible.

Unless I'm missing something (I usually am), it seems like the two best ways this can be achieved is to either have:

1. A DS grid with an array for each grid square that holds the information for that cell. The DS grid layout would mimic the 64x64 world grid. I've heard that using arrays is super fast as they are stored as pointers in memory and get automatically cleaned up (and they can also be saved easily).

2. A DS list that holds all the variables for each square (which will need to include every combination of the grids x and y (so that there is one row for each square)). This instinctively sounds simpler but given that I'll need a square for each unique x and y combination I'll need to have 7680 rows x 10+ bits of information in the list, which will need to be searched through very often. I'm not sure if this would be better or worse than having a DS grid with 7680 squares, with 7680 individual arrays for each one :(

Any feelings as to which one will be faster/"better"?

As always, any help is much appreciated.
 

Flashpants

Member
Thanks JuJu, we've already started to go down that route, so it's good to hear you say that you don't think it's monumentally better to go for the list :banana:
 
Did not know about this. Why is that the case?
Basically, a map can find the corresponding value to a key in, on average, O(1), which means it takes the same amount of time to find a value if there's 10 entries or 10 000 (this depends a bit, but that's the simplified version), whereas the time it takes to find a value in a list grows with the number of entries.
 
Top