使用指向频道的指针

Is it good practice to use pointer to channel? For example I read the data concurrently and pass those data map[string]sting using channel and process this channel inside getSameValues().

func getSameValues(results *chan map[string]string) []string {
    var datas = make([]map[string]string, len(*results))
    i := 0
    for values := range *results {
        datas[i] = values
        i++
    }
}

The reason I do this is because the chan map[string]string there will be around millions of data inside the map and it will be more than one map.

So I think it would be a good approach if I can pass pointer to the function so that it will not copy the data to save some resource of memory.

I didn't find a good practice in effective go. So I'm kinda doubt about my approach here.

It usually not good practice to use pointers to channels.

The size of a channel value is equal to the size of a pointer. The size is independent of the number of values in the channel.

You do not reduce copying by using a pointer to a channel because copying the pointer has the same cost as copying the channel.

In Go, there are five categories of value that are passed by reference rather than by value. These are pointers, slices, maps, channels and interfaces.

Copying a reference value and copying a pointer should be considered equal in terms of what the CPU has to actually do (at least as a good approximation).

So it is almost never useful to use pointers to channels, just like it is rarely useful to use pointers to maps.

Because your channel carries maps, the channel is a reference type and so are the maps, so all the CPU is doing is copying pointers around the heap. In the case of the channel, it also does goroutine synchronisation too.

For further reading, open Effective Go and search the page for the word 'reference'.