Python中超过1个字节对象的相同内存地址

发布于 2025-02-09 07:05:20 字数 348 浏览 3 评论 0原文

如果内存地址参考1内存的字节,则如果我将元素附加到该列表,则如何表示“ 139754451527680”的内存地址保持不变?

为了澄清,我了解数组/列表的元素是元素位置的指示

。大于1个字节对象?

如果我们在谈论8个字节对象,只是(内存地址 * 8)吗?

import sys
a = 1
sys.getsizeof(a)  # 28 bytes (24 bytes int overhead; 4 bytes integer value)
id(a)             # 9788960  ---> 28 memory slot / memory addresses????

If a memory address references 1 byte of memory, how does the memory address of say '139754451527680' for an empty list stay the same if I append elements to that list?

To clarify, I understand that elements of an array/list are pointers to the elements location, etc...

My question is specific to if the memory address is the address of 1 byte of memory, how does the address 'get calculated' for larger than 1 byte objects?

Is it just the (memory address * 8) if we are talking about an 8 byte object?

import sys
a = 1
sys.getsizeof(a)  # 28 bytes (24 bytes int overhead; 4 bytes integer value)
id(a)             # 9788960  ---> 28 memory slot / memory addresses????

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文