Yinon Burgansky
Yinon Burgansky
MModular
Created by Yinon Burgansky on 3/29/2024 in #questions
Returning a reference from a factory
Thanks, having the compiler optimize it automatically sounds great, which will hopefully make the code less verbose than rust.
10 replies
MModular
Created by Yinon Burgansky on 3/29/2024 in #questions
Returning a reference from a factory
To clarify the question, there are multiple concepts each with its own options: - Ownership, single or multiple references, mutable or immutable, deciding when to free an object. - Memory allocation strategy, heap or stack. - value semantics, by value or by reference (memory address). A struct can decide decide on its value semantics by default, but the struct size could change by compile time parameters passed from the outside, you might want to pass it by reference instead of by value, or to allocate it locally on the stack or globally in the heap depending on the use case. I would like to know how does Mojo plan to deal with the various legal combinations of these options?
10 replies
MModular
Created by Yinon Burgansky on 3/29/2024 in #questions
Returning a reference from a factory
I think there is terminology issue. So IIUC reference is only used to solve the problem of ownership where there could be multiple references to the same object. Where here is about a memory allocation strategy, allocate it on the heap and pass it around by its memory address.
10 replies
MModular
Created by Yinon Burgansky on 3/29/2024 in #questions
Returning a reference from a factory
If it is a large struct which should be heap allocated and we want to hint the compiler it should be passed around by reference and not by value.
10 replies