Skip Navigation

Should you use slices of pointers to structs?

www.willem.dev Should you use a slice of pointers to structs in Go/Golang?

What is the difference between a slice of pointers and a slice of values? And when should you use one or the other? This article explains.

Should you use a slice of pointers to structs in Go/Golang?

While writing Go, you might might run into the following situation: You want to collect the results of a function in a slice. However, the function returns a pointer.

You might then ask yourself:

What kind of slice should I use? A slice of values or a slice of pointers?

Let’s make this a bit more concrete.

0
0 comments