Is there something I’m not understanding about the Mojo memory model?
I hope this is an easy question and someone will know the obvious thing I'm doing wrong. I have this minimal example code that demonstrates an issue I’m having.
main.mojo
:
command_line_mod.mojo
:
If I build and run this with mojo build main.mojo; ./main
I get a segmentation fault. Why?10 Replies
Congrats @nairby, you just advanced to level 1!
Global variables are currently a bit of a sharp edge and aren't really supported 🙃
It's not an intentional omission, it's just a feature that needs some work to make happen
that should work eventually roughly "as-is" once the feature lands
Ah that explains why some of the global var use was working and some wasn't. Thanks
Is there a rough timeline of when that might expected to be supported? Is this poor program design and therefore low priority?
Considering migrating a Fortran application to mojo (in the future) so my ideas on storing data in global vars in modules may be outdated
globals are definitely still useful, they are just difficult to deal with and init at times so it hasn't been at the top of the priority list yet
I think you can try moving stuff into a "globals" object you pass around through the call tree
And if your global data is imutable, you could use
alias
depending on how you treat it you can avoid most issues with the borrow checker
Hmm ok interesting, I'll have to look into that more. Thanks again
saying monad without saying monad?
:squints: oh, yeah, huh lol