Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 ALL


  The Go Pointer Magic

Go is a language with the pointer type, by which we canPass pointer into a function and update value in-place.Add methods to a struct as (* T) A, which is different from (T) A().However, the pointer is type-safe in Go, meaning that there are such restrictions of the pointer.Different types of pointers are unconvertible.Pointer type cannot be used for calculation.Pointer types cannot be compared, either == nor !=.No mutual assignment between different pointer-type variables.For example, *int cannot be converted to *int32in the following code.func main() {...

3,907 0       POINTER GOLANG UNSAFE


  Understand unsafe in GoLang

Before going to understand unsafe package in GoLang, the first thing needs to talk about is the pointer in GoLang. If you have a background of C language, you must know what pointer means and its usage. With pointer, you are free to operate any data at memory level which means you have great power, but this means that you have great responsibility as well. That's why it might be considered unsafe in lots of cases.Take a look at a simple example of doubling an integer.package mainimport "fmt"func double(x int) { x += x}func main() { var a = 3 double(a) fmt.Println(a) // 3}The above ...

17,485 0       GOLANG UNSAFE ZERO-COPY