Source file
test/strcopy.go
Documentation: test
1
2
3
4
5
6
7
8
9
10 package main
11
12 import (
13 "reflect"
14 "unsafe"
15 )
16
17 func main() {
18 var (
19 buf = make([]byte, 2<<10)
20 large = string(buf)
21 sub = large[10:12]
22 subcopy = string([]byte(sub))
23 subh = *(*reflect.StringHeader)(unsafe.Pointer(&sub))
24 subcopyh = *(*reflect.StringHeader)(unsafe.Pointer(&subcopy))
25 )
26 if subh.Data == subcopyh.Data {
27 panic("sub and subcopy have the same underlying array")
28 }
29 }
30
View as plain text