what is the scene to use mapaccess1_fat and mapaccess2_fat?

123 views
Skip to first unread message

xie cui

unread,
Dec 16, 2020, 1:39:55 AM12/16/20
to golang-nuts

Axel Wagner

unread,
Dec 16, 2020, 8:41:36 AM12/16/20
to xie cui, golang-nuts
A little bit of guesswork, again (I'm not working on the compiler)

`mapaccess1` is obviously for map index expressions of the form `m[key]`, while `mapaccess2` is for assignments like `a, ok := m[key]`.

And AIUI the non-`_fat` versions are used if the value-type of the map is too large to fit into a pre-allocated array of zero-bytes. In that case, the runtime gets passed a separate pointer to a zero-value of that type to use as the default - I assume, in that case the compiler emits code to allocate (on the stack or the heap) zeroed memory of the appropriate size and passes that to `mapaccess1_fat`.

Hope that helps, even though I'm guessing :)

On Wed, Dec 16, 2020 at 7:40 AM xie cui <cuiw...@gmail.com> wrote:
https://github.com/golang/go/blob/master/src/runtime/map.go#L554

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/9ef8570c-42b1-441f-bd57-64b6da3cba0bn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages