Using pointer to channel

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

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'.


It is poor practice to use pointers to channels, maps, functions, interfaces, or slices for efficiency.

Values of these types have a small fixed size independent of the length or capacity of the value. An internal pointer references the variable size data.

Channels, maps, and functions are the same size as a pointer. Therefore, the runtime cost of copying a value of these types is identical to copying a pointer to the value.

Interfaces are two × the size of a pointer, and slices are three × the size of a pointer. The cost of copying a value of these types is higher than copying a pointer. That extra copying cost is often lower or equal to the cost of dereferencing the pointer.