C
C#9mo 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
Jimmacle9mo 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
Messiah9mo ago
aren't instances of classes stored in the heap? aka low performance
Jimmacle
Jimmacle9mo 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
Messiah9mo ago
ouch
Jimmacle
Jimmacle9mo ago
no because it's not a real problem, seems like you're assuming it is
Messiah
Messiah9mo ago
so treat it as not a problem until it becomes one, yes?
Jimmacle
Jimmacle9mo ago
right
Messiah
Messiah9mo ago
gotcha!
Jimmacle
Jimmacle9mo 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
Messiah9mo 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
Jimmacle9mo ago
the heap and stack are all just RAM
Angius
Angius9mo ago
I mean C# will use the VM and will use the heap
Jimmacle
Jimmacle9mo ago
you'll need to use the CLR anyway
Messiah
Messiah9mo ago
fair point 😆
Jimmacle
Jimmacle9mo 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
Messiah9mo ago
lovely, thanks!
Accord
Accord9mo 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.