duancaishun4812 2019-02-09 04:43
浏览 79

是否有任何简便的方法来查找一个结构实例需要多少内存(包括**指向它的大小)? [重复]

This question already has an answer here:

Two cases in particular:

First: big.Int

regardless of the number stored, unsafe.Sizeof returns 16. It obviously doesn't count the data that represents the number, just a pointer or reference to it. Is there a call I can make to account for all the memory being used by the big.Int?

Second: linked list

If I have a struct which includes pointers to things which have pointers and so on. Obviously unsafe.Sizeof only returns the size of the member pointer, not the things it points to and certainly not recursively.

Are there easy ways of accessing how much memory such things are using in total?

https://play.golang.org/p/bGbQ_4pZP7W

</div>
  • 写回答

1条回答 默认 最新

  • dongxian7471 2019-02-09 09:26
    关注

    No, there is no "magic" or easy way to do this. The only option is to recurse the structure yourself. And even then, it's often a matter of definition what counts toward memory usage. As an example, you'd almost certainly not want to count circular references more than once.

    评论

报告相同问题?

悬赏问题

  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?