3 ms·
Thanks, for the paper Steve, I'll edit the post with due credit. What would be the appropriate description for Rust's memory model? Automatic scoped memory man
by miguelraz 5y ago
Thanks, for the paper Steve, I'll edit the post with due credit.
What would be the appropriate description for Rust's memory model? Automatic scoped memory management with opt-in reference counting?
- Diggsey 5y ago"Memory model" is also an academic term which (among other things) describes how memory behaves WRT to concurrent opreations, so I would not use it in this context. Memory management is the correct term. Rust the language does not do any memory management: memory management is a feature of the standard library. I would say that the Rust standard library (the `alloc` crate specifically) provides types that safely encapsulate allocation and deallocation of memory. This is enabled by automatic destructor calls on stack-allocated variables when they go out of scope. (However, note that destructors need not deallocate memory). Again, this part works exactly the same in C++. In C++ when a type's constructor acquires some resource, and its destructor releases that resource (in this case the resource being memory) it is referred to as "Resource Acquisition Is Initialization" or RAII. https://en.wikipedia.org/wiki/Memory_model_(programming) https://en.wikipedia.org/wiki/Memory_model_(programming)
- oconnor663 5y agoYeah "exactly the same as C++" is really very accurate here, and there's really not much else to say. I find it a little odd that the Wikipedia article even mentions "reference counting is optional", because it makes Arc sound like a central feature of the language, but I don't think anyone thinks about shared_ptr that way.
- quietbritishjim 5y agoTo add to that, I can imagine implementing a sort of fully garbage collected smart pointer in both languages (but maybe not compacting), but surely no one would describe either of them as an "optionally garbage collected language".
- pjmlp 5y agoJust extending your explanation that Ada also does RAII, there they are called controlled types. And to certain extent, C++ has influenced Turbo Pascal/Delphi as well with similar approach.