Memory Management

from Introduction to Rust

  • It seems like there is a lack of prerequisite knowledge about memory, so let’s learn about it.

Understanding how programs use memory (1) Understanding how programs use memory (3)

  • Explanation of stack memory, heap memory, and data memory, easy to understand.

  • Data memory is where things with a confirmed size at compile time are placed.

    • Things like magic numbers (which are immutable)
    • Global variables (which are mutable)
  • How strings are stored

    • The length of a string cannot be changed.

    • The length of a string cannot be changed.

    • The length of a string can be changed because it is stored in the heap memory.

  • Since there are some drawbacks to using heap memory in terms of speed, it seems like it’s important to use stack memory effectively. Understanding how programs use memory (4)

  • Ah, so “stack overflow” means the stack is overflowing! (?)(blu3mo)

    • I understand now.
  • It’s easy to understand the flow of values during function execution.

  • I’ve never even thought about allocating and freeing heap memory before.

    • Rust is a language that doesn’t require memory management, it’s great.
    • It seems like it’s done by this thing called “garbage collection”.