From 864944400263d9d8d1a31b538841f8ad6edfc76b Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Tue, 8 Nov 2011 16:26:03 -0800 Subject: [PATCH] FAQ: update R=bradfitz, r, dsymonds, edsrzf, rsc CC=golang-dev https://golang.org/cl/5345055 --- doc/go_faq.html | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/doc/go_faq.html b/doc/go_faq.html index aeed537956..b2a65a6795 100644 --- a/doc/go_faq.html +++ b/doc/go_faq.html @@ -496,8 +496,8 @@ It's possible to use these ideas to construct something analogous to type-safe Unix pipes. For instance, see how fmt.Fprintf enables formatted printing to any output, not just a file, or how the bufio package can be completely separate from file I/O, -or how the crypto packages stitch together block and -stream ciphers. All these ideas stem from a single interface +or how the image packages generate compressed +image files. All these ideas stem from a single interface (io.Writer) representing a single method (Write). And that's only scratching the surface.

@@ -681,7 +681,7 @@ examples and also have them be statically checked. Can I convert a []T to an []interface{}?

-Not directly because they do not have the same representation in memory. +Not directly, because they do not have the same representation in memory. It is necessary to copy the elements individually to the destination slice. This example converts a slice of int to a slice of interface{}: @@ -841,10 +841,13 @@ for more information about how to proceed. When are function parameters passed by value?

-Everything in Go is passed by value. A function always gets a copy of the +As in all languages in the C family, everything in Go is passed by value. +That is, a function always gets a copy of the thing being passed, as if there were an assignment statement assigning the -value to the parameter. For instance, copying a pointer value makes a copy of -the pointer, not the data it points to. +value to the parameter. For instance, passing an int value +to a function makes a copy of the int, and passing a pointer +value makes a copy of the pointer, but not the data it points to. +(See the next section for a discussion of how this affects method receivers.)

@@ -946,6 +949,12 @@ floating-point numbers. The default size of a floating-point constant is float64.

+

+At the moment, all implementations use 32-bit ints, an essentially arbitrary decision. +However, we expect that int will be increased to 64 bits on 64-bit +architectures in a future release of Go. +

+

How do I know whether a variable is allocated on the heap or the stack?

@@ -966,9 +975,10 @@ garbage-collected heap to avoid dangling pointer errors.

-In the current compilers, the analysis is crude: if a variable has its address -taken, that variable is allocated on the heap. We are working to improve this -analysis so that more data is kept on the stack. +In the current compilers, if a variable has its address taken, that variable +is a candidate for allocation on the heap. However, a basic escape +analysis recognizes some cases when such variables will not +live past the return from the function and can reside on the stack.

Concurrency

@@ -1008,7 +1018,7 @@ effectively equal to the number of running goroutines.

-Programs that perform concurrent computation should benefit from an increase in +Programs that perform parallel computation should benefit from an increase in GOMAXPROCS. (See the runtime package's documentation.) @@ -1227,16 +1237,16 @@ it now. Gccgo's run-time support uses glibc. control; it is compiled with a version of the Plan 9 C compiler that supports segmented stacks for goroutines. -Work is underway to provide the same stack management in -gccgo. +The gccgo compiler also implements segmented +stacks, supported by recent modifications to its linker.

Why is my trivial program such a large binary?

-The gc tool chain (5l, 6l, and 8l) only -generate statically linked binaries. All Go binaries therefore include the Go +The linkers in the gc tool chain (5l, 6l, and 8l) +do static linking. All Go binaries therefore include the Go run-time, along with the run-time type information necessary to support dynamic type checks, reflection, and even panic-time stack traces.

@@ -1316,7 +1326,7 @@ For instance, pidigits depends on a multi-precision math package, and the C versions, unlike Go's, use GMP (which is written in optimized assembler). Benchmarks that depend on regular expressions (regex-dna, for instance) are -essentially comparing Go's stopgap regexp package to +essentially comparing Go's native regexp package to mature, highly optimized regular expression libraries like PCRE.

@@ -1373,7 +1383,7 @@ the declaration declares a to be a pointer but not b; in Go

-	var a, b *int;
+	var a, b *int
 

declares both to be pointers. This is clearer and more regular. @@ -1381,11 +1391,11 @@ Also, the := short declaration form argues that a full variable declaration should present the same order as := so

-	var a uint64 = 1;
+	var a uint64 = 1
 
has the same effect as
-	a := uint64(1);
+	a := uint64(1)
 

Parsing is also simplified by having a distinct grammar for types that -- 2.48.1