C
C#13mo ago
triplemocha

❔ Any issue with this for a game?

I'm making a game. I have a Array2D object that holds "Cells". So, each grid cell has data. Each cell can be a wall, path, etc. Every cell has two List<int> collections. If I have a 1000x1000 map that holds a cell in each, will I have any issues? Seems like a lot having 1000x1000x2 lists. Each list is estimated to hold at most 10 items.
9 Replies
Jimmacle
Jimmacle13mo ago
napkin math says that's under 100MB of memory worst case if that's what you mean by "any issues"
triplemocha
triplemocha13mo ago
Okay. I was just thinking that's a lot of lists for a single map. One map will be loaded at a time, so it sounds like a non-issue.
Jimmacle
Jimmacle13mo ago
depending on what exactly you're doing you might want a structure more cache-friendly, but that's a bridge to cross when you get to it
triplemocha
triplemocha13mo ago
What structure would be that?
Jimmacle
Jimmacle13mo ago
for example if you were scanning neighboring cells for items in their lists you might want to make them structs with a fixed number of fields so the data is kept locally in the array so the neighbors are more likely to already be in cache when you need them not something to worry about unless you're running into performance issues related to memory access time
triplemocha
triplemocha13mo ago
I see. I wanted Cell to be a struct before, but someone recommended a class. Little easier to work with then writing ref frequently. I think it should be an easy fix though if I had to switch. I used classes in C++ and did this whole thing and moved it to C#. So, I’m used to cached/bit wise copies. I did hear from MS that structs should be less than 16kb in C#. That confused me. It didn't matter in C++.
Jimmacle
Jimmacle13mo ago
it matters in C++ too, i assume the C# docs suggest that to avoid possible issues like large copies or overflowing the stack more quickly
triplemocha
triplemocha13mo ago
I see.
Accord
Accord13mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts