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