gpt4 book ai didi

Tcl 内存管理

转载 作者:行者123 更新时间:2023-12-04 18:16:47 25 4
gpt4 key购买 nike

我在一些文章中看到过 Tcl 使用引用计数来进行垃圾收集。我想知道这意味着什么,因为据我所知,Tcl 没有指针或引用,所以每个变量只被引用一次。那么它到底在计算什么呢?

最佳答案

这个想法是 Tcl 对值而不是变量进行引用计数。

让我们引用 the wiki page on copy-on-write semantics :

Each value (Tcl_Obj) has a reference count. Whenever the value is passed to a command or assigned to a variable the reference count is incremented and no copy is made. When a value is to be changed the implementation first checks the reference count. If the count is 1 then there is no other reference to the value and it can be changed in place. If the count is greater than 1 then there are other references to this value. If the value were to be changed in place then those references would also be changed. To prevent this a copy of the value is made (with new reference count of 1) and the copy is changed in place.



这个解释中唯一缺少的是,当一个值的引用计数下降到 belov 1 时,该值被销毁。

有关核心信息,请阅读 Tcl_Obj manual page 的“对象的存储管理”部分和 these discussions .

关于Tcl 内存管理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11496135/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com