Replies: 1 comment 3 replies
-
Perhaps I am mistaken, but I assumed the following:
I agree that it would be nice to make this more clear in the documentation. As for creating an array on the stack, I believe you should be able to create that through the aforementioned But mojo is very young, and I think a LOT is going to change. For example, they want to make this a memory safe language (unlike C++). But without In fact, if modular wants to entice away rustaceans to mojo, they will need to make sure it's a memory-safe language (I was surprised...though I should not have been...to see segmentation faults again after being mercifully free of them for so long using rust). I am actually curious how mojo is going to handle the equivalent of rust's In rust, there are only a handful of ways to heap allocate, but more importantly, rust's ownership rules track who is responsible for freeing the memory (and rust's drop method is called implicitly by the compiler when the variable goes out of scope). |
Beta Was this translation helpful? Give feedback.
-
Hi all, I started playing with mojo in the last few days. I wrote a more comprehensive set of notes from my experience here: https://github.com/dsharlet/mojo_comments
One of the issues mentioned there is it would be really helpful to be able to declare a chunk of intermediate storage and control where it goes (registers, stack, heap). Right now, the only way I can find to allocate memory looks like a heap allocation, which is not very appropriate for use cases like the one I documented above.
As far as I can tell, it's not possible to have some kind of array "native" to the language itself (much like Python), which seems like it will be necessary in order to have allocations be placed on the stack.
#400 (sort of) mentions this as should be deferred to library authors, but I'm not sure that makes sense for allocations intended to be on the stack. This seems like it needs compiler support and understanding, maybe even some higher level conceptual support (it's not necessarily the case that a stack is conceptually a thing at all, and just an implementation detail...). This is not currently mentioned in the roadmap (unless I missed it), and I think it might require some deep thought with how this interacts with the language design, so doing it early could be important.
Maybe just adding some
alloca
-like thing that works with the pointer types used for heap allocations currently would work? It would be a headache to use though, because presumably it couldn't be used inside a helper function, like all the existing heap allocation usages I've seen (such as to make aMatrix
object).Beta Was this translation helpful? Give feedback.
All reactions