Rust memory management: Difference between revisions
From wikinotes
No edit summary |
|||
Line 9: | Line 9: | ||
|} | |} | ||
</blockquote><!-- Documentation --> | </blockquote><!-- Documentation --> | ||
= General = | |||
<blockquote> | |||
== Stack == | |||
<blockquote> | |||
The stack is | |||
* a LIFO | |||
* push=add, pop=remove (from the top) | |||
* only supports fixed-size datatypes | |||
* fast | |||
</blockquote><!-- Stack --> | |||
== Heap == | |||
<blockquote> | |||
* access provided through pointers (a fixed-size, usable on stack) | |||
* slower | |||
</blockquote><!-- Heap --> | |||
== Ownership == | |||
<blockquote> | |||
* Objects have a single owner at once | |||
* When owner goes out of scope, value is dropped | |||
</blockquote><!-- Ownership --> | |||
</blockquote><!-- General --> |
Revision as of 15:09, 7 February 2023
Rust uses ownership semantics for memory management.
Documentation
official tutorial https://doc.rust-lang.org/stable/book/ch04-00-understanding-ownership.html
General
Stack
The stack is
- a LIFO
- push=add, pop=remove (from the top)
- only supports fixed-size datatypes
- fast
Heap
- access provided through pointers (a fixed-size, usable on stack)
- slower
Ownership
- Objects have a single owner at once
- When owner goes out of scope, value is dropped