gpt4 book ai didi

memory-management - 什么是Dyon的内存模型?

转载 作者:行者123 更新时间:2023-12-03 11:45:33 26 4
gpt4 key购买 nike

Dyon Tutorial说它使用“生命周期”,而不是垃圾回收或手动内存管理。但是,这种生命周期模型与Rust中的所有权有何不同?

Dyon has a limited memory model because of the lack of a garbage collector. The language is designed to work around this limitation. - The Dyon Programming Language Tutorial



这个模型到底有多有限?由于这个限制,是否存在一个示例,导致Dyon无法运行内存管理代码?

最佳答案

链接的Dyon book包含以下说明:

Lifetimes are about references

A lifetime is about the references stored inside a variable. All references outlive variables they are stored in. Variables can not store references to themselves, because it can not outlive itself.

In order to put a reference inside a variable, the lifetime checker must know that the reference outlives the variable.

Because of the lifetime checker, all memory in Dyon is an acyclic graph.



因此,主要限制是引用不能进行任何循环。也就是说,不可能表示圆形节点列表,也不能让子对象保留对其父对象的引用。

这些限制也适用于Rust,但Rust还提供了解决方法。引用计数类型( RcArc)与弱引用(请参阅 std::rc::Weak )结合可以创建循环引用。也可以在 unsafe构造(即原始指针)之后进行循环。

另请参阅(特定于 rust ,但适用大多数原则):
  • Why can't I store a value and a reference to that value in the same struct?
  • 关于memory-management - 什么是Dyon的内存模型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61939447/

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