Value types and reference types in Go

Value types and reference types in Go

1. The difference between value type and reference type
1. Value type: int series, float series, bool, string, array and structure
2. Reference type: pointer, slice slice, map, pipe chan, interface interface, etc.

2. Use features
1. Value type: directly store value, stack allocation, copy directly copy all values, damage performance
2. Reference type: storage address, use heap allocation, only copy address when copying

3. Matters needing attention
When there is no variable referencing this address, the data space corresponding to the address becomes garbage, and it is recycled by Gc

After reading it, it is a little helpful to yourself, please like and support, thank you

Guess you like

Origin blog.csdn.net/yyq1102394156/article/details/113872191