OLD | NEW |
1 Go Slices: usage and internals | 1 Go Slices: usage and internals |
2 5 Jan 2011 | 2 5 Jan 2011 |
3 Tags: slice | 3 Tags: slice, technical |
4 | 4 |
5 Andrew Gerrand | 5 Andrew Gerrand |
6 | 6 |
7 * Introduction | 7 * Introduction |
8 | 8 |
9 Go's slice type provides a convenient and efficient means of working with sequen
ces of typed data. Slices are analogous to arrays in other languages, but have s
ome unusual properties. This article will look at what slices are and how they a
re used. | 9 Go's slice type provides a convenient and efficient means of working with sequen
ces of typed data. Slices are analogous to arrays in other languages, but have s
ome unusual properties. This article will look at what slices are and how they a
re used. |
10 | 10 |
11 * Arrays | 11 * Arrays |
12 | 12 |
13 The slice type is an abstraction built on top of Go's array type, and so to unde
rstand slices we must first understand arrays. | 13 The slice type is an abstraction built on top of Go's array type, and so to unde
rstand slices we must first understand arrays. |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 c := make([]byte, len(b)) | 224 c := make([]byte, len(b)) |
225 copy(c, b) | 225 copy(c, b) |
226 return c | 226 return c |
227 } | 227 } |
228 | 228 |
229 A more concise version of this function could be constructed by using `append`.
This is left as an exercise for the reader. | 229 A more concise version of this function could be constructed by using `append`.
This is left as an exercise for the reader. |
230 | 230 |
231 * Further Reading | 231 * Further Reading |
232 | 232 |
233 [[http://golang.org/doc/effective_go.html][Effective Go]] contains an in-depth t
reatment of [[http://golang.org/doc/effective_go.html#slices][slices]] and [[htt
p://golang.org/doc/effective_go.html#arrays][arrays]], and the Go [[http://golan
g.org/doc/go_spec.html][language specification]] defines [[http://golang.org/doc
/go_spec.html#Slice_types][slices]] and their [[http://golang.org/doc/go_spec.ht
ml#Length_and_capacity][associated]] [[http://golang.org/doc/go_spec.html#Making
_slices_maps_and_channels][helper]] [[http://golang.org/doc/go_spec.html#Appendi
ng_and_copying_slices][functions]]. | 233 [[http://golang.org/doc/effective_go.html][Effective Go]] contains an in-depth t
reatment of [[http://golang.org/doc/effective_go.html#slices][slices]] and [[htt
p://golang.org/doc/effective_go.html#arrays][arrays]], and the Go [[http://golan
g.org/doc/go_spec.html][language specification]] defines [[http://golang.org/doc
/go_spec.html#Slice_types][slices]] and their [[http://golang.org/doc/go_spec.ht
ml#Length_and_capacity][associated]] [[http://golang.org/doc/go_spec.html#Making
_slices_maps_and_channels][helper]] [[http://golang.org/doc/go_spec.html#Appendi
ng_and_copying_slices][functions]]. |
OLD | NEW |