usagi / rust-memory-container-cs

Rust Memory Container Cheat-sheet
MIT License
2.37k stars 80 forks source link

Include the useful suggestions from reddit #2

Closed usagi closed 4 years ago

usagi commented 4 years ago

From: https://www.reddit.com/r/rust/comments/idwlqu/rust_memory_container_cheatsheet_publish_on_github/g2bsbso/?utm_source=reddit&utm_medium=web2x&context=3

Internal sharing? -[no]--> Allocates? -[no]--> Internal mutability? -[no]--> Ownership? -[no]-----------------------------------> &mut T
      \                     \                                    \                     `-[yes]----------------------------------> T
       \                     \                                    \
        \                     \                                    `-[yes]-> Thread-safe? -[no]--> Internal references? -[no]---> Cell<T>
         \                     \                                                       \                               `-[yes]--> RefCell<T>
          \                     \                                                       \
           \                     \                                                       `-[yes]-> Internal references? -[no]---> AtomicT
            \                     \                                                                                  \ `-[one]--> Mutex<T>
             \                     \                                                                                  `--[many]-> RwLock<T>
              \                     \
               \                     `-[yes]------------------------------------------------------------------------------------> Box<T>
                \         
                 `-[yes]-> Allocates? -[no]-------------------------------------------------------------------------------------> &T
                                    \
                                     `-[yes]-> Thread-safe? -[no]---------------------------------------------------------------> Rc<T>
                                                           `-[yes]--------------------------------------------------------------> Arc<T>
Reply

And, I have an interest to several suggestions for a correctness or details. But, the cheat-sheet favor to a newbiews, and the right columns is not a type, yes I know. I'll make an update with include these reddit users suggestions to the rev1 or a later.

usagi commented 4 years ago

Working draft, rev.1-alpha

image

usagi commented 4 years ago

Working draft, rev.1-beta

image

foobles commented 4 years ago

Cell<T> and RefCell<T> should be moved to the stack-allocation section. Those types do not do any heap allocs whatsoever.

usagi commented 4 years ago

@theInkSquid Oh that's right, it was my mistaken. I'll fixup soon. Very thank you🙏

usagi commented 4 years ago

Working draft, rev.1-gamma

image