我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

在Go中将指针用作地图键是否安全?

Suppose we add a value to a map using a pointer as the key. Could the memory address of this pointer ever change? If so, will looking it up in the map fail because when it was inserted, it had a different memory address?

Could the memory address change, in the pointers-as-uints sense? Yes, but outside of the unsafe package go doesn't expose pointers as uints. So, will looking it up in the map fail? No.

See more at the spec. The linked section even includes a pointer-keyed map as an example.

近期文章

  • (继续)如何使用toml文件?
  • 从函数返回语句转到数组切片
  • 附加片性能差..为什么呢?
  • 在ANSI C中实现无溢出系统堆栈
  • 防止元帅在结构的字符串字段中转义引号
  • 意外的分号或换行符,如果没有
  • 频道被封锁时,频道会保持秩序吗?
  • 如何处理“ fmt” golang库软件包进行CLI测试
  • memstats结构中的哪些字段仅引用堆,仅引用堆栈
  • 如何在golang中有效地连接字符串数组和字符串
  • 从接口类型到实际类型的强制类型断言
  • Go项目结构-最佳做法
  • 如何在Golang Beego中解析表单数组
  • Go mgo软件包中的连接池
  • 去除以大数(big.Int)
  • Go运行时使用的线程数
  • 为什么fmt.Println在Google App Engine中不起作用
  • 您如何在流中上传文件?
  • 从protobuf更新数据
  • 如何直接从终端/命令行运行Go(lang)代码?

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华