mirror of
https://github.com/chai2010/advanced-go-programming-book.git
synced 2025-05-24 20:52:22 +00:00
ch2-05: 完善例子, 增加缓冲的释放工作
This commit is contained in:
parent
c6bc5a45a3
commit
50151b643f
@ -199,6 +199,8 @@ import "unsafe"
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
buf := NewMyBuffer(1024)
|
buf := NewMyBuffer(1024)
|
||||||
|
defer buf.Delete()
|
||||||
|
|
||||||
copy(buf.Data(), []byte("hello\x00"))
|
copy(buf.Data(), []byte("hello\x00"))
|
||||||
C.puts((*C.char)(unsafe.Pointer(&(buf.Data()[0]))))
|
C.puts((*C.char)(unsafe.Pointer(&(buf.Data()[0]))))
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,8 @@ import "unsafe"
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
buf := NewMyBuffer(1024)
|
buf := NewMyBuffer(1024)
|
||||||
|
defer buf.Delete()
|
||||||
|
|
||||||
copy(buf.Data(), []byte("hello\x00"))
|
copy(buf.Data(), []byte("hello\x00"))
|
||||||
C.puts((*C.char)(unsafe.Pointer(&(buf.Data()[0]))))
|
C.puts((*C.char)(unsafe.Pointer(&(buf.Data()[0]))))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user