|
Rory McGuire |
at Sep 21, 2012 at 9:09 pm
|
⇧ |
| |
I believe slices work like the code below:
type slice struct {
start *uintptr
length int64
capacity int64
}
example := make([]byte, 0, 10) // slice{start:calloc(*10*), length:*0*,
capacity:*10*}
return example // return the VALUE slice{start:calloc(*10*), length:*0*,
capacity:*10*}
example2 := make([]byte, len(example), cap(example))
copy(example2, example)
return example2 // return the VALUE slice{start:calloc(*10*), length:*0*,
capacity:*10*} but its a new COPY
On Friday, 21 September 2012 16:02:18 UTC+2, Meir wrote:Is it true that slices/arrays/maps/structs always get passed/returned by
reference (i.e. not by value)?
The following small code snippet demonstrates that slices do get returned
by reference:
http://play.golang.org/p/bVP5wPCcQ2If I am overgeneralizing, could you please tell me what the rule is?
Thanks!
Meir
--