There are 2 options for cutting off:

  1. list := make([]*Person, 5)
  2. list := make([]Person, 5)

How will the 2 'variant behave when passing the slice to methods / functions?
Will there be an overhead, due to the fact that objects are cut, not pointers (there will be copies of people every time they are transmitted)?
Or because Do we still have the cut content will be transmitted by reference?

    1 answer 1

    A slice / slice is always a structure of three machine words (pointer, length / length, capacity). Regardless of what elements inside.

    The array would be passed by value. list := [5]Person{} will transfer 5 * sizeof(Person) bytes.

    • I did not ask about the array / slice. And how will the content of the slice behave, if there are not pointers, but a value. Will there be copies of the slice content each time the method / function is called? - TomX01
    • one
      I replied that there would be no copy, since the cut is always "passed by reference." - Ainar-G