R 中的“retracemem”有什么作用?
回答关于 tracemem
最近,我了解了 retracemem
。 ?retracemem
的帮助和其中的示例让我一无所知。
retracemem
实际上做了什么?为什么?它没有做我想象的那样,即将一个对象指向另一个对象的内存位置,至少据我所知。
我尝试了像 .Internal(inspect())
这样的神奇调用,它对我没有任何作用:
> a = 1:10
> b = a[-1]
> .Internal(inspect(a))
@00000000087AE578 13 INTSXP g0c4 [NAM(2)] (len=10, tl=23336) 1,2,3,4,5,...
> .Internal(inspect(b))
@00000000087AE8E8 13 INTSXP g0c4 [NAM(2)] (len=9, tl=7208) 2,3,4,5,6,...
> retracemem(b,retracemem(a))
> .Internal(inspect(b))
@00000000087AE8E8 13 INTSXP g0c4 [NAM(2)] (len=9, tl=7208) 2,3,4,5,6,...
After answering about tracemem
recently, I learned about retracemem
. The help for ?retracemem
and the example therein leave me unenlightened.
What does retracemem
actually do and why? It doesn't do what I thought it would do, i.e. point one object to the memory location of another, at least as far as I can tell.
I tried a wizardly invocation like .Internal(inspect())
, which performs no magic for me:
> a = 1:10
> b = a[-1]
> .Internal(inspect(a))
@00000000087AE578 13 INTSXP g0c4 [NAM(2)] (len=10, tl=23336) 1,2,3,4,5,...
> .Internal(inspect(b))
@00000000087AE8E8 13 INTSXP g0c4 [NAM(2)] (len=9, tl=7208) 2,3,4,5,6,...
> retracemem(b,retracemem(a))
> .Internal(inspect(b))
@00000000087AE8E8 13 INTSXP g0c4 [NAM(2)] (len=9, tl=7208) 2,3,4,5,6,...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为 retracemem() 只能让您标记一个变量副本,这不会产生 Tracemem 语句(例如上面的
b
它实际上只是的副本>a
没有第一个元素),因为是从同一源变量派生的,因此您可以继续观察副本/部分副本传播并查看它们是否从同一源派生。例如,A 的内存如何被复制/传播:
但话又说回来,我可能完全错了......
I think
retracemem()
just lets you tag a variable copy, which wouldn't produce a tracemem statement (such as ab
above which is really just a copy ofa
sans the first element), as being derived from the same source variable, so you can continue to watch the copies/partial copies propagate and see that they derive from the same source.For example, how does A's memory get copied/propagated:
But then again, I could be entirely wrong...