gpt4 book ai didi

rust - 'Zero Cost Abstraction' 是什么意思?

转载 作者:行者123 更新时间:2023-12-04 14:39:09 25 4
gpt4 key购买 nike

我在探索 Rust 时遇到了这个术语。
我看到了关于这个的不同类型的解释,但仍然不太明白。
在嵌入式 Rust 书中,它说

Type states are also an excellent example of Zero Cost Abstractions

  • the ability to move certain behaviors to compile time execution or analysis.

These type states contain no actual data, and are instead used asmarkers.

Since they contain no data, they have no actual representation inmemory at runtime:


这是否意味着运行时更快,因为运行时没有内存?
如果有人能以易于理解的方式解释它,请欣赏它。

最佳答案

零成本抽象意味着添加更高级别的编程概念,如泛型、集合等不会带来运行时成本,只有编译器时间成本(代码编译会更慢)。任何对零成本抽象的操作都与您使用低级编程概念(for 循环、计数器、ifs 等)手动编写匹配功能一样快。

关于rust - 'Zero Cost Abstraction' 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69178380/

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