Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Xik
Mar 10, 2011

Dinosaur Gum
What is the benefit of using a
code:
map[string]SomeStruct
vs
code:
map[string]*SomeStruct
Or put another way: Why bother with the mental gymnastics of deciding if the struct is "large enough" to replace it with pointers to the struct and just always do so? Is there some overhead to resolving the pointer compared to not doing so?

Adbot
ADBOT LOVES YOU

Xik
Mar 10, 2011

Dinosaur Gum

Joda posted:

In terms of raw performances, a value map is probably faster than a reference map on iteration or repeated access due to lower rate of cache aliasing for objects contiguous in memory

Ok, so as a general rule if you just plan to frequently read from a map of immutable structs then there are benefits to just using a value map. Otherwise mutating the map or the structs themselves use pointers?

Xik
Mar 10, 2011

Dinosaur Gum

Linux Nazi posted:

pre-write structs to deal with the dozens, sometimes hundreds of different responses? By literally writing dozens, sometimes hundreds of structs? Really?

Yeah this is what is done in statically typed languages in my experience. Tooling usually makes it easier, like in C#/VS you can just import a huge json structure and it'll create all the classes for you. A couple of refactoring commands later they are all in seperate files with correct formatting and naming conventions applied.

This probably comes down to personal preference but I would for sure prefer a stack of structs over a map of interface{}'s.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply