book
book copied to clipboard
4.1 Understanding Ownership, Memory and Allocation: unfortunately
- I have searched open and closed issues and pull requests for duplicates, using these search terms:
- unfortunately
- I have checked the latest
mainbranch to see if this has already been fixed, in this file:- src/ch04-01-what-is-ownership.md
Description of the problem: The text says:
Unfortunately, we can’t put a blob of memory into the binary for each piece of text whose size is unknown at compile time
- The word
Unfortunatelydescribes a situation that is not desirable to change. - It wouldn't be a fortune if a blob of memory were allocated in the binary for each piece of text.
Suggested fix:
- Replace
Unfortunately, we canwithWe can.
Thanks for reporting. That section was indeed awkward to read. This is what GPT-4 suggests:
In Rust, string literals are known at compile time, enabling their direct incorporation into the final executable. This integration contributes to the speed and efficiency of string literals. However, these benefits are intrinsically linked to the immutability of string literals. It's impractical to embed a memory segment into the binary for each text string whose size is not predetermined at compile time and may vary during program execution.
I don't trust GPT-4 to be good enough for the job, as beginners should not face wild hallucinations in an introductory text, even if they sound correct at first glance. The GPT-4 text has several complicated words that don't contribute to the understanding. The GPT-4 paragraph looks like it were a rephrased variant of the current section from the book.
Here's how I would rewrite the section from the book:
Since strings literal are immutable and known at compile time, their text is embedded in the final executable. This way, their lifetime is "forever", thus there is no need to track ownership of string literals. For a
String, on the other hand, the length and text can change while the program is running, therefore its text cannot be embedded in the final executable.
For me, as a non native speaker, GPT-4 is a great help, its wording is typically much better than mine. Of course it is not always 100% correct, so we have to do carefully proof-reading. You are correct, the cited GPT-text is a rewording of the book, but I like it: https://chat.openai.com/share/7d67c747-7d1d-4e93-b012-1d59188eacd3 For me, your text appears grammatically wrong: Should "strings literal" be "string literals"? And your text section is not that great to read, sorry. This is how GPT-4 would reword it: https://chat.openai.com/share/8a02da98-5fab-451a-9792-8bb1f252ddff
[EDIT] Sorry, first pasted link was wrong.
You're right, I made a typo and actually meant "string literals".
Thanks! I agree that this is a bit confusing, and at first blush your suggestion is a nice improvement. We'll chat and see if we want to run with that or iterate on it further!