我在不同的单元格[memory containing variables (I will not go to the bit level)]有一排苹果,其中一些是空的[cells containing garbage / empty value]。
我拿出了一个。它在单元格 3 [logical address = 3]。
我把它涂成蓝色(在我使用未来技术克隆它之后,用于不变性演示)[committed an operation on it, same could go for addition for integers]。
我查看了放哪里,虽然 4 号单元是免费的,但 3 号单元也是(因为“原始”苹果已不存在了)!所以我把它放回了单元格 3 [and although we get a "new" apple, it has the same address]。
t 也是如此(注意 id 是 CPython 中变量的内存地址),但由于我们在这里讨论的是“苹果链”(字符串由字符序列组成,所以我们有考虑我们必须继续序列的空间量,所以如果我的记忆看起来像(_ 代表任意垃圾数据,'^' 代表空间)
H e l l o _ _ _ _ _ B O O M
^ string pointer points here
我想将字符串更改为"Hello you",我可能会考虑使用空闲空间:
H e l l o ^ y o u _ B O O M
^ string pointer points here
但是如果我想将字符串更改为"Hello world!",我将不得不在其他地方寻找长度为"Hello world!" 的空闲空间(我们可能在"BOOM" 之后找到它,这很可能在垃圾中收集的环境,看看你的 ID 有什么不同):
H e l l o ^ y o u _ B O O M _ H e l l o ^ w o r l d ! _ G A R B A G E
^ string pointer points here