C
C#14mo ago
Messiah

❔ Storing static data

I'm working with lots of static data (best example I can think of are items in a game), would you store this data in a struct, static classes, or what? I'm mainly looking for performance and best practices. How would you implement this? I'd appreciate some keywords I could google as well, not sure what to search for this.
17 Replies
Jimmacle
Jimmacle14mo ago
depends how static it really is hardcoding it in classes is an option, you could also store the data on disk and load it once when the game starts
Messiah
MessiahOP14mo ago
aren't instances of classes stored in the heap? aka low performance
Jimmacle
Jimmacle14mo ago
did you profile an implementation and decide that's a problem? that's microoptimization territory, if you haven't implemented anything yet don't get preoccupied with it all of this will be on the heap no matter what static classes are on the heap, structs that are members of classes are on the heap, etc
Messiah
MessiahOP14mo ago
ouch
Jimmacle
Jimmacle14mo ago
no because it's not a real problem, seems like you're assuming it is
Messiah
MessiahOP14mo ago
so treat it as not a problem until it becomes one, yes?
Jimmacle
Jimmacle14mo ago
right
Messiah
MessiahOP14mo ago
gotcha!
Jimmacle
Jimmacle14mo ago
i would personally be more concerned with cache coherency but that is still pretty deep in "don't care unless you know it's actually a problem" territory that would mostly depend on when/how you search for pieces of that data
Messiah
MessiahOP14mo ago
I was kinda hoping to run this tool as a script, so having to boot the c# virtual machine, allocate heap, read the data in 0.01 seconds then dump everything seemed counter intuitive
Jimmacle
Jimmacle14mo ago
the heap and stack are all just RAM
Angius
Angius14mo ago
I mean C# will use the VM and will use the heap
Jimmacle
Jimmacle14mo ago
you'll need to use the CLR anyway
Messiah
MessiahOP14mo ago
fair point 😆
Jimmacle
Jimmacle14mo ago
also, if you have more than 1MB of data the default stack size wouldn't be big enough anyway unless it's lots of strings, which again would be on the heap regardless especially if this is a one-shot script type of thing it's not worth worrying about might be different if this was in the hot path of a game loop or something
Messiah
MessiahOP14mo ago
lovely, thanks!
Accord
Accord14mo 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