One of the most promising candidates to replacing C as the default language for e.g., embedded programs is RUST lang. One of the most important pillar of RUST is the memory management, because it comes without a (dynamic) garbage collector. The garbage collector approach is replaced by and so called ownership approach. Purpose of ownership is to manage heap, not the stack. Heap is the free floating memory assigned to an executed program.
The ownership concept assigns an owner to a memory address. As soon as the owner is out of the program execution scope, the memory gets free. A scope is e.g., determined between the following two brackets { and }. In RUST we do not have memory leaks coming from misused alloc and free calls.
So far so good, but the common beginners mistake happen with quite common assignments like a=b. If b is a simple type (fix sized) and not an Object it works as expected; b will give its value to a. Object types such as String just copy the pointer and all related meta-data, not the value itself. So if an and b go out of scope, RUST would free both. This would lead to a safety issue. RUST will per definition avoid those situations by just invalidating the assigned Object (here b). If we would like to use both variables we have to make a deep copy. A deep copy is made via the function .clone().
Same applies for function calls.
-
Archives
- March 2025
- February 2025
- January 2025
- December 2024
- October 2024
- July 2024
- June 2024
- May 2024
- April 2024
- March 2024
- January 2024
- December 2023
- November 2023
- October 2023
- September 2023
- August 2023
- July 2023
- June 2023
- May 2023
- April 2023
- March 2023
- February 2023
- January 2023
- December 2022
- November 2022
- August 2022
- June 2022
- March 2022
- February 2022
- January 2022
- December 2021
- November 2021
- October 2021
- August 2021
- July 2021
- June 2021
- April 2021
- December 2019
-
Meta