From 5f5a1127865f96f04fc4be82c2940f1c532e7aac Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 14 May 2019 17:18:04 +0100 Subject: [PATCH] wip --- talk.txt | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 talk.txt diff --git a/talk.txt b/talk.txt new file mode 100644 index 0000000..9980de0 --- /dev/null +++ b/talk.txt @@ -0,0 +1,84 @@ + +In many respects Rust is a competent but not particularly novel +language. + +Powerful. + +Reference to Blub languages. + +B======================================================================B + +[ MM survey slide ] + +Firstly, I'm going to go into some detail about Rust's one very novel +property: it's approach to memory management. Let us consider, +particularly, dynamically allocated memory. + +Until now there have been basically two approaches: + +In lower-level languages like C, C++ and assembler, you as the +programmer must know whenever memory allocation is occurring, and +control when that memory is freed, usually with explicit code. +Mistakes lead to bugs - often, bugs which are very hard to track down. +There are some static checkers, and coding conventions, which help to +reduce the number of these bugs but they are still a big problem even +with the most careful software development practices. + +In higher-level languages, memory allocation is often implicit and +deallocation is handled automatically by a garbage collector. This is +convenient for the programmer. But it requires support from a +language runtime, which is awkward in some environments and makes it +hard to interface to other languages. And it costs performance - +sometimes, a lot of performance. Traditionally, garbage-collected +languages have focused on programmer convenience, or programming +language power, rather than performance. + +[ MM survey slide + Rust ] + +Rust has a different approach. Each object in a Rust program has +exactly one owner; for a local variable that owner is the variable. +For an object in a complex data structure, the data structure is the +owner (and of course that data structure has, in turn, an owner). In +many ways this resembles informal notions of object ownership which +programmers have typically used in C and C++ to make their code +comprehensible. + +But in Rust the ownership is known to the language, and the rules +surrounding ownership are enforced by the compiler. When an object +ceases to have an owner, it is freed. + +This ownership system is used not only for dynamically allocated +objects, but for local variables, and statically allocated objects. + +[ Borrowing example slide ] https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html#mutable-references + +To allow an object to be accessed other than through owner, Rust +formalises the notion of borrowing. An object can be borrowed by +writing the ampersand, giving a reference. The compiler checks that +the object will outlive the reference. + +[ dangling reference error example https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html#dangling-references ] + +Borrows (that is, references) come in two kinds: mutable and +immutable. You can have many immutable references at once. A mutable +reference permits modification, and provides exclusive access. + +[ Borrowing example slide ] https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html#mutable-references + +That's what the `mut' is doing in that example. + + + + +You can lend Objects which + + +This ownership is +known to the + + +tends to lead to + + + +write explicit code allocate memory, and and free allre -- 2.30.2