Can pointers be used as map keys in Go?

Suppose we add a value to a map using a pointer as a key. Can the memory address of this pointer ever change? If so, will it be distorted on the card, because when it was inserted, it had a different memory address?

+4
source share
1 answer

Can a memory address change in the sense of pointers? Yes, but outside the unsafe go package does not set pointers as uints. So, will it look on the map? No.

More details in the specification . The linked section even includes an example map with a pointer.

+7
source

Source: https://habr.com/ru/post/1622680/


All Articles