Is it a value copy to pass large MAP between functions in golang?

I am learning golang development gadgets. There is a scenario in which you need to pass data of map [string] [] string type. Each time, about 5W pieces of data are saved in map and passed to other functions for processing. If you do so, will it consume a lot of memory?. But it seems that map can"t pass a value by passing a pointer? Do you have any good suggestions in this situation? Thank you

Mar.04,2021

I recommend you take a look at an article written by a blogger http://colobu.com/2017/01/05/.


similar to map and slice, references are passed without a copy of the value.

package main

import "fmt"

func main() {
    var pointerMap map[string]int = map[string]int{
        "a" : 1,
    }
    pointerB := pointerMap
    pointerB["a"] = 2;
    fmt.Printf("%v", pointerMap)
}

is still the value passed, except that the passed "value" is a 1-word address

[ https://play.golang.org/p/ozH.]

package main

import (

)
f "fmt"

)

func alter_map (a map [int] int) {

a[1] = 2
f.Printf("%p\n", &a) //!!!!!!!!!!!!!1
f.Printf("%p\n", a)//map

}

func main () {

a := make(map[int]int, 2)
a[2] =1
f.Printf("%p\n", &a) //!!!!!!!!!!!!!!
f.Printf("%p\n", a) //map
alter_map(a) //map

f.Println(a)

}

Menu