11 ms·
How about something like a Go interface which is essentially two pointers and the data itself.
by pkaye 4y ago
How about something like a Go interface which is essentially two pointers and the data itself.
- Groxx 4y agoThat's the same thing they're describing, and equivalent to what Go does for map[string]int64 (plus or minus minor details about how strings are optimized). The map has its two slices (pointer + length + capacity = 8*3 times two slices) and the string needs a separate allocation somewhere because it's essentially a pointer to a slice of bytes. All of which is true for almost all reasonably efficiency-focused languages, Rust and Go included - it's just how you make a compact hashmap.
- Yoric 4y agoDoes Go perform interning of strings?
- Groxx 4y agoCompile-time strings, I think so? In that all identical strings simply point to the same data. Otherwise no.
- xh-dude 4y agoUse of Go’s runtime reflection to produce a struct definition would result in one instance of the key string, many instances of the numeric value This approach is available/implemented in the standard library, the whole story with JSON in Go is includes a few different approaches but this is definitely anticipated.