4 ms·
You wonder based on what? Static will put something in the binary itself and it will be memory mapped in, which won't even need to be directly allocated.
by CyberDildonics 4y ago
You wonder based on what? Static will put something in the binary itself and it will be memory mapped in, which won't even need to be directly allocated.
- vlovich123 4y agoThe apostrophe isn’t superfluous. ‘Static in this context refers to static lifetime. Lifetimes have absolutely 0 impact on runtime.
- CyberDildonics 4y agoI'm not sure what this has to do with the parent post or how it contradicts what I said. https://doc.rust-lang.org/std/keyword.static.html https://doc.rust-lang.org/std/keyword.static.html
- vlovich123 4y agoYou are referring to static variables which have ‘static lifetime. OP is asking about ‘static lifetime and whether GC would somehow collect garbage more precisely (it wouldn’t). You’re basically talking past each other.
- celeritascelery 4y agoHow would you get a static lifetime without a static object?
- unshavedyak 4y agoUnrelated to the above convo, but: An owned object can be bound by a static lifetime, for example. Eg, `fn foo<T: 'static>(t: T){}\n foo(String::new());`
- vlovich123 4y agoMore dangerous / less common, but you can also launder lifetimes through unsafe where you use ‘static to indicate “it’s not possible to verify lifetime at compile time but I promise you this will outlive you”. An example of this would be storing a reference that is reference counted but you don’t want the lifetime to bleed out into the type signature.
- ben-schaaf 4y agoBox::leak for one.
- remram 4y agoBox::leak() will make a &'static. You can also use lazy_static! to dynamically make a static global constant.
- bonzini 4y ago'static is a lifetime here.