Hello, everyone! I can't one thing. Where Rust are types like local const, global const, local static and global static stored. I know, Rust stored global const and global static in static data area (bss or data), but I can't understand, where Rust stores another types: local const and local static in stack or static data area? If they are stored on the stack, do they follow the concept of ownership? Are they deleted from memory when they exit the scope?
There's no distinction between a local or global static
item other than visibility. You can think of static
items as having no owner (they can't be moved and never get destructed, for example).
const
items work almost more like macros; you can't count on them having a consistent address for example, but you can't count on them having distinct addresses either. When using a const
value, it may get promoted to a static
in some situations if eligible; otherwise, they act like other values: they may be put on the stack or in a register, etc, and the values will be destructed in the normal way.
Here's some examples of using const
s that then go out of scope, etc.
Thanks!
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.