3 ms·
This seems to be all about heap-allocated objects. Can the ownership machinery reason about lifetimes of stack-allocated objects at all? For example, i would l
by twic 7y ago
This seems to be all about heap-allocated objects. Can the ownership machinery reason about lifetimes of stack-allocated objects at all?
For example, i would like to declare a buffer on the stack, read some data into it, make const pointers into the buffer, put those pointers in heap-allocated structs, put those structs in a vector, and do some manipulation. As long as all the heap-allocated structs expire before i return from the function where the buffer was declared, this is entirely safe, but if they escape, i'm in trouble.
- WalterBright 7y ago> Can the ownership machinery reason about lifetimes of stack-allocated objects at all? It already does. If you compile with the -dip1000 switch, you'll be unable to escape references to the stack for @safe code.