如何获取Itcl类成员变量的引用?
假设我有以下结构:
package require Itcl
itcl::class AAA {
private variable m_list {}
constructor {} {
fill m_list list
}
}
如何获取 m_list 上的引用以便编写
foreach elem $reference {.......}
考虑到列表确实很大,我不想复制它!
Say I have the following structure:
package require Itcl
itcl::class AAA {
private variable m_list {}
constructor {} {
fill m_list list
}
}
How to get a reference on the m_list in order to write
foreach elem $reference {.......}
Consider that list is really big and I don't want to copy it!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Tcl 变量使用写时复制语义。您可以安全地传递一个值,为其分配多个变量,而不必担心它占用更多的内存空间。
例如,
上面的代码将产生两个巨大的列表,一个包含 x 和任意 y 都指向的原始数据,另一个包含仅 z 指向的额外元素 123。在 lappend 语句之前,只有一份列表副本,并且所有三个变量都指向它。
Tcl variables use copy-on-write semantics. You can safely pass a value around, assigning multiple variables to it, without worrying about it taking up more space in memory.
For example
The above code will result in two giant lists, one with the original data that both x any y point at, and one with the extra element of 123 that only z points to. Prior to the lappend statement, there was only one copy of the list and all three variables pointed at it.
以下是如何获取类成员的引用:
Here is how to get a reference on the member of a class: