You've already forked comprehensive-rust
mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-10-09 10:55:26 +02:00
docs: improve language in memory-management section (#2882)
I asked Gemini to review the English for inconsistencies and grammar mistakes. This is the result and I hope it's useful! As a non-native speaker, it is hard for me to evaluate the finer details, so let me know if you would like to see changes (or even better: make them directly in the PR with the suggestion function).
This commit is contained in:
@@ -34,7 +34,7 @@ in context.
|
||||
|
||||
- C++ has tools like smart pointers (`unique_ptr`, `shared_ptr`) that take
|
||||
advantage of language guarantees about calling destructors to ensure memory is
|
||||
freed when a function returns. It is still quite easy to mis-use these tools
|
||||
freed when a function returns. It is still quite easy to misuse these tools
|
||||
and create similar bugs to C.
|
||||
|
||||
- Java, Go, and Python rely on the garbage collector to identify memory that is
|
||||
@@ -43,10 +43,10 @@ in context.
|
||||
has a runtime cost and is difficult to tune properly.
|
||||
|
||||
Rust's ownership and borrowing model can, in many cases, get the performance of
|
||||
C, with alloc and free operations precisely where they are required -- zero
|
||||
cost. It also provides tools similar to C++'s smart pointers. When required,
|
||||
other options such as reference counting are available, and there are even
|
||||
crates available to support runtime garbage collection (not covered in this
|
||||
C, with alloc and free operations precisely where they are required --
|
||||
zero-cost. It also provides tools similar to C++'s smart pointers. When
|
||||
required, other options such as reference counting are available, and there are
|
||||
even crates available to support runtime garbage collection (not covered in this
|
||||
class).
|
||||
|
||||
</details>
|
||||
|
@@ -164,7 +164,7 @@ Key points:
|
||||
would take place. After the move, `s1` would be in a valid but unspecified
|
||||
state. Unlike Rust, the programmer is allowed to keep using `s1`.
|
||||
|
||||
- Unlike Rust, `=` in C++ can run arbitrary code as determined by the type which
|
||||
- Unlike Rust, `=` in C++ can run arbitrary code as determined by the type that
|
||||
is being copied or moved.
|
||||
|
||||
[`std::move`]: https://en.cppreference.com/w/cpp/utility/move
|
||||
|
@@ -29,7 +29,7 @@ destructor can run here to free up resources.
|
||||
|
||||
<details>
|
||||
|
||||
Students familiar with garbage-collection implementations will know that a
|
||||
Students familiar with garbage collection implementations will know that a
|
||||
garbage collector starts with a set of "roots" to find all reachable memory.
|
||||
Rust's "single owner" principle is a similar idea.
|
||||
|
||||
|
@@ -14,7 +14,7 @@ Programs allocate memory in two ways:
|
||||
|
||||
- Heap: Storage of values outside of function calls.
|
||||
- Values have dynamic sizes determined at runtime.
|
||||
- Slightly slower than the stack: some book-keeping needed.
|
||||
- Slightly slower than the stack: some bookkeeping needed.
|
||||
- No guarantee of memory locality.
|
||||
|
||||
## Example
|
||||
|
Reference in New Issue
Block a user