跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • 如何可以得知,运行的某个时候,产生的目标字典占用了多少内存?
未分類
19 4 月 2020

如何可以得知,运行的某个时候,产生的目标字典占用了多少内存?

如何可以得知,运行的某个时候,产生的目标字典占用了多少内存?

資深大佬 : qazwsxkevin 53

比如想得知,在函数运行后,return 回来的 dict 占了多少 MB 内存这样?
大佬有話說 (6)

  • 資深大佬 : casparchen

    你这个标题对仗不整齐啊,逗号少一个。

    如何才可以得知,
    运行的某个时候,
    产生的目标字典,
    占用了多少内存。

    看看这样是不是好多了 ?

  • 資深大佬 : si

    我搜索了一下:
    Python 获取对象所占内存大小方法:
    sys.getsizeof()
    内置函数__sizeof__()

  • 資深大佬 : iamwho

    sys.getsizeof()

    ?

  • 主 資深大佬 : qazwsxkevin

    @casparchen 最后一个逗号可以不必吧。。。

    @si 我第一认知也是这个,只是这个似乎是不准确。。。

    @iamwho 这个似乎是不准确的。。。

    看了一晚网上关于这方面的各种说法,问的这个问题,似乎在 Python 上无解。。。
    不过不重要了,打算把磁盘上 53MB 的内容放入字典传来传去了

  • 資深大佬 : iamwho

    @qazwsxkevin #4

    Return the size of an object in bytes. The object can be any type of object. All built-in objects will return correct results, but this does not have to hold true for third-party extensions as it is implementation specific.

    Only the memory consumption directly attributed to the object is accounted for, not the memory consumption of objects it refers to.

    https://docs.python.org/3/library/sys.html#sys.getsizeof

  • 資深大佬 : yucongo

    试试 memoryprofile 包 或 ipython 里的 %mprun, 参考 https://stackoverflow.com/questions/563840/how-can-i-check-the-memory-usage-of-objects-in-ipython/58362611#58362611

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具