From the course: Build with AI: Developing a Discord Bot Conversationally

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Rust memory model

Rust memory model

- [Instructor] Rust ownership system zero cost memory safety without garbage collection, allows for very important workflows in high performance settings. The stack stores the values and the pointers, and the heap stores the dynamic data, and then the compiler tracks every reference at compile time. And what this does is it eliminates data races, null pointers, and use after free bugs. And this allows you to get into a more sophisticated way of memory safety. Let's go ahead and walk through what that looks like. Inside of this left blue box here, we see that there's a fixed size note as a compile time; this is the last-in, first-out allocation. We also have fast access, so CPU cache-friendly, no indirection. We have value types: primitive, structs, et cetera, pointer storage, function frames. This would be local variables and return addresses. And then if we look at the stack variables, this is the green, the purple,…

Contents