CS 631-02 Systems Foundations — Meeting Summary¶
Date: February 3, 2026
Time: 2:50 PM Pacific Time (US and Canada)
Meeting ID: 882 2309 0019
Quick Recap¶
- The session compared memory management in C and Rust, including stack allocation, heap usage, and Rust’s ownership model.
- Greg demonstrated differences in memory safety and string handling through code examples and live demos.
- The class reviewed an approach to implementing a scanner in Rust, covering enums, structs, methods, and the
Optiontype. - An announcement was made about upcoming lab work on parsing and related materials.
Next Steps¶
Instructor (Greg)¶
- Push the side-by-side C and Rust memory model example code to the in-class repository.
- After the lab due date, post an idiomatic Rust version of
scan2.rsto the in-class repository. - Post the next lab (parser) and the new GitHub repository for the lab and next round of tests.
- Post additional lecture notes for the Thursday session.
Students¶
- Extend
scan2(both C and Rust versions) to support the full set of tokens specified for Lab 1. - If not already done, accept the GitHub assignment for Lab 1 and ensure all required files are committed and pushed.
- If developing locally, clone and test the Lab 1 submission on the Beagle machine (or another machine) to verify that all files are present and the code runs as expected.
- Attend office hours (Greg or Shreyas) for questions about the material or assignments.
Summary¶
Memory Management in C and Rust¶
- The discussion covered stack, heap, and global memory in C, and contrasted these with Rust’s ownership and borrowing systems.
- String handling in Rust was introduced, including string slices (
&str) and mutable strings (String). - After a brief break, the class examined C and Rust memory allocation scenarios and reviewed the
scan2.rsprogram.
Rust vs. C Memory Safety¶
- Examples highlighted stack allocation, dangling pointers, and memory leaks in C.
- Rust’s compiler-enforced ownership rules were shown to prevent common issues such as:
- Dangling pointers
- Aliasing mutable references
- Use-after-free errors
- Rust’s string slicing and ownership model were contrasted with C’s string handling. In particular, Rust disallows returning references to stack-allocated data that would become invalid, preventing the dangling pointer pattern common in C.
Rust Scanner Implementation Overview¶
- The Rust implementation of a scanner was compared with the C version.
- Key Rust concepts covered:
- Enums and structs for token representation
- Methods and associated functions
- The
Optiontype as a safe alternative to null - Token scanning and printing were demonstrated, emphasizing differences in memory management and string handling between C and Rust.
- Greg announced that an idiomatic Rust version of the scanner would be posted after the lab deadline and that the next lab would focus on parsing, with new lecture notes and a GitHub repository forthcoming.