What’s the point of having pointers in Go?

Pointers are usefull for several reasons. Pointers allow control over memory layout (affects efficiency of CPU cache). In Go we can define a structure where all the members are in contiguous memory: type Point struct { x, y int } type LineSegment struct { source, destination Point } In this case the Point structures are … Read more

Range references instead values

The short & direct answer: no, use the array index instead of the value So the above code becomes: package main import “fmt” type MyType struct { field string } func main() { var array [10]MyType for idx, _ := range array { array[idx].field = “foo” } for _, e := range array { fmt.Println(e.field) … Read more

What is a “fat pointer”?

The term “fat pointer” is used to refer to references and raw pointers to dynamically sized types (DSTs) – slices or trait objects. A fat pointer contains a pointer plus some information that makes the DST “complete” (e.g. the length). Most commonly used types in Rust are not DSTs but have a fixed size known … Read more

How do I do a literal *int64 in Go?

The Go Language Specification (Address operators) does not allow to take the address of a numeric constant (not of an untyped nor of a typed constant). The operand must be addressable, that is, either a variable, pointer indirection, or slice indexing operation; or a field selector of an addressable struct operand; or an array indexing … Read more

Pointers vs. values in parameters and return values

tl;dr: Methods using receiver pointers are common; the rule of thumb for receivers is, “If in doubt, use a pointer.” Slices, maps, channels, strings, function values, and interface values are implemented with pointers internally, and a pointer to them is often redundant. Elsewhere, use pointers for big structs or structs you’ll have to change, and … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)