Hi! I’m getting started with Odin and I don’t have a lot of experience with manually-managed memory languages.
I have trouble understanding how structs are passed around: I have a proc returning a struct with specific data, and it’s called inside a loop. What I end up seeing is that all returned structs are actually the same reference, so the code ends up updating the same struct over and over. Here is an example.
My understanding is that structs are allocated on the stack and when returned, they would be copied to the caller stack so they have a different reference. But I’m seeing that even a small struct with just an int field is actually not copied when returned.
Could someone please explain how structs are handled in memory? I think I’m missing a piece because it seems weird to me that for instance if you made a string builder inside a loop, you would not actually get a different builder each time.
Thank you!