【Rust深入浅出】翻译What Is Ownership

Ownership是Rust编程语言中的一套内存管理规则,它通过编译时的检查确保程序的安全性和效率,避免了垃圾收集的开销。程序员需要遵循这些规则来分配和释放内存。随着对Ownership系统的深入理解,开发者能更好地编写出高效且无内存安全问题的代码,尤其在处理如strings等常见数据结构时。
摘要由CSDN通过智能技术生成

What Is Ownership?

Ownership is a set of rules that govern how a Rust program manages memory. All programs have to manage the way they use a computer’s memory while running. Some languages have garbage collection that regularly looks for no-longer-used memory as the program runs; in other languages, the programmer must explicitly allocate and free the memory. Rust uses a third approach: memory is managed through a system of ownership with a set of rules that the compiler checks. If any of the rules are violated, the program won’t compile. None of the features of ownership will slow down your program while it’s running.

Owership 是一套规则,他用来治理Rust怎样管理内存,所有的程序都有去管理内存的方法,他们使用计算机及的内存并运行,有一些语言拥有垃圾收集,在运行期间他们定期的查看没有长期使用的内存,有一些其他语言,开发者必须明确的分配可用的的内存,Rust使用了第三种方式;内训管理是通过系统的ownership,一套规则,在编译的时候检查,如果任何规则被违反,这个程序将不会被编译,没有功能会因为ownership减慢你的程序运行

Because ownership is a new concept for many programmers, it does take some time to get used to. The good news is that the more experienced you become with Rust and the rules of the ownership system, the easier you’ll find it to naturally develop code that is safe and efficient. Keep at it!

因为ownership对应开发者来说是一个新的概念,会用一些时间去适应它,ownership 的好消息是你会对rust的规则有更多经验,你将会找到简单的开发方式,是更安全而且高效的,坚持使用它!

When you understand ownership, you’ll have a solid foundation for understanding the features that make Rust unique. In this chapter, you’ll learn ownership by working through some examples that focus on a very common data structure: strings.

这时候你明白了ownership。你将会拥有坚实的基础去明白这个功能让Rust独一无二,在这一章中,你将会通过一些例子(非常常用的数据结构:string)学习到ownership怎样工作

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Alaia.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值