03-pointers/

directory
v0.0.0-...-35bbffe Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2015 License: Apache-2.0

README

Pointers - Language Syntax

Pointers provide a way to share data across function boundaries. Having the ability to share and reference data with a pointer provides flexbility. It also helps our programs minimize the amount of memory they need and can add some extra performance.

Notes

  • Use pointers to share data.
  • Values in Go are always pass by value.
  • "Value of", what's in the box. "Address of" ( & ), where is the box.
  • The (*) operator declares a pointer variable and the "Value that the pointer points to".

1.5 Garbage Collection

figure1

https://golang.ir/doc/effective_go.html#pointers_vs_values

http://www.goinggo.net/2013/07/understanding-pointers-and-memory.html

http://www.goinggo.net/2014/12/using-pointers-in-go.html

Contiguous Stack Proposal

Go Escape Analysis Flaws

Rick Hudson GC Talk

https://blog.golang.org/go15gc

https://en.wikipedia.org/wiki/Tracing_garbage_collection

Code Review

Pass by Value (Go Playground)

Sharing data I (Go Playground)

Sharing data II (Go Playground)

Stack vs Heap (Go Playground)

Advanced Code Review

Contiguous Backing Array (Go Playground)

Exercises

Exercise 1

Part A Declare and initialize a variable of type int with the value of 20. Display the address of and value of the variable.

Part B Declare and initialize a pointer variable of type int that points to the last variable you just created. Display the address of , value of and the value that the pointer points to.

Template (Go Playground) | Answer (Go Playground)

Exercise 2

Declare a struct type and create a value of this type. Declare a function that can change the value of some field in this struct type. Display the value before and after the call to your function.

Template (Go Playground) | Answer (Go Playground)


Ardan Labs Ardan Studios GoingGo Blog


All material is licensed under the Apache License Version 2.0, January 2004.

Directories

Path Synopsis
advanced
example1
Sample program to show how the backing array for a referene type can be placed contiguous in memory with the header value.
Sample program to show how the backing array for a referene type can be placed contiguous in memory with the header value.
Sample program to show the basic concept of pass by value.
Sample program to show the basic concept of pass by value.
Sample program to show the basic concept of using a pointer to share data.
Sample program to show the basic concept of using a pointer to share data.
Sample program to show the basic concept of using a pointer to share data.
Sample program to show the basic concept of using a pointer to share data.
Sample program to show varaibles stay on or escape from the stack.
Sample program to show varaibles stay on or escape from the stack.
exercises
exercise1
Declare and initialize a variable of type int with the value of 20.
Declare and initialize a variable of type int with the value of 20.
exercise2
Declare a struct type and create a value of this type.
Declare a struct type and create a value of this type.
template1
Declare and initialize a variable of type int with the value of 20.
Declare and initialize a variable of type int with the value of 20.
template2
Declare a struct type and create a value of this type.
Declare a struct type and create a value of this type.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL