First published at 14:46 UTC on January 9th, 2018.
Today Were going to start talking about ownership. I thought that going over an actual project would be more beneficial than some random snip-it of code. To follow along clone my repo from github.
In the next video we'll go over the string type.…
MORE
Today Were going to start talking about ownership. I thought that going over an actual project would be more beneficial than some random snip-it of code. To follow along clone my repo from github.
In the next video we'll go over the string type.
git clone https://github.com/BearzRobotics/cache_cleaner.git
Ownership rules:
Each value in Rust has a variable that’s called its owner.
There can only be one owner at a time.
When the owner goes out of scope, the value will be dropped.
Stack
he stack stores values in the order it gets them and removes the values in the opposite order.
last in first out. eg a stack of plates.
must be a know and fixed size (pointer is also a know fixed size)
Heap
unknown data size.
The operating system finds an empty spot somewhere in the heap that is big enough, marks it as
being in use, and returns to us a pointer, which is the address of that location.
Reading data from the heap is slower because we have to follow a pointer to get.
When our code calls a function, the values passed into the function (including, potentially,
pointers to data on the heap) and the function’s local variables get pushed onto the stack.
When the function is over, those values get popped off the stack.
LESS