Nick!
Nick!
MModular
Created by whatever on 12/26/2024 in #questions
List memory preallocation
Does memory preallocation give me a performance improvement in Mojo?
It's very difficult to reason about program performance without benchmarking. Modern compilers are smart and can provide great performance without manual intervention. Whether or not manually specifying the capacity of your list can improve performance depends upon what capacity value you're specifying, and how many elements you put in your list. In general, there will likely be a small (but measurable) performance difference when reserving a large number of elements, but not when reserving a small number of elements (≤ 4).
5 replies
MModular
Created by whatever on 12/26/2024 in #questions
List memory preallocation
The "size" of the list is about to be renamed to "len", which hopefully clarifies what it means. The "capacity" of a container is the number of elements that memory has been allocated for. It is always >= the length. If you know any Rust, see this explanation. So yes, List[Int](capacity=5) gives you a list of length zero, with memory reserved for 5 elements.
5 replies
MModular
Created by Lil'Nish on 12/26/2024 in #questions
Strange CLI Hang
(Beyond that, I don't know anything about this issue.)
6 replies
MModular
Created by Lil'Nish on 12/26/2024 in #questions
Strange CLI Hang
There's an existing thread about this issue with Magic.
6 replies
MModular
Created by christian_drake on 12/4/2024 in #questions
Help I have skill issues
fn main():
random.seed()
for _ in range(10):
var x: UInt8 = 0
random.randint(UnsafePointer.address_of(x), 1, 0, 42)
print(x)
fn main():
random.seed()
for _ in range(10):
var x: UInt8 = 0
random.randint(UnsafePointer.address_of(x), 1, 0, 42)
print(x)
22 replies
MModular
Created by christian_drake on 12/4/2024 in #questions
Help I have skill issues
Check out seed()
22 replies
MModular
Created by christian_drake on 12/4/2024 in #questions
Help I have skill issues
if ptr points to a buffer, then size would be the number of random numbers that you want to put into the buffer
22 replies
MModular
Created by christian_drake on 12/4/2024 in #questions
Help I have skill issues
randint is designed to fill an entire buffer with random numbers
22 replies
MModular
Created by christian_drake on 12/4/2024 in #questions
Help I have skill issues
If your pointer points to a single integer, then size must be 1, otherwise you'll be writing to invalid memory locations.
22 replies
MModular
Created by christian_drake on 12/4/2024 in #questions
Help I have skill issues
ptr: The pointer to the memory area to fill. size: The number of elements to fill.
22 replies
MModular
Created by christian_drake on 12/4/2024 in #questions
Help I have skill issues
check the description of each argument in the docs
22 replies
MModular
Created by christian_drake on 12/4/2024 in #questions
Help I have skill issues
It fills the chunk of memory that the pointer points to
22 replies
MModular
Created by christian_drake on 12/4/2024 in #questions
Help I have skill issues
No worries
22 replies
MModular
Created by christian_drake on 12/4/2024 in #questions
Help I have skill issues
Hopefully that's a useful starting point. Let me know if you need more info.
22 replies
MModular
Created by christian_drake on 12/4/2024 in #questions
Help I have skill issues
Per the docs for randint, it doesn't return anything. (There is no -> in its signature.) So number is None. The random number is written to the first argument—the pointer. Also, SIMD[Dtype.uint8, 1] is the same type as UInt8. This is discussed here. Also, you don't need to allocate your integer on the heap (alloc) in order to obtain an unsafe pointer to an integer. You can use address_of to get a pointer to a stack-allocated integer.
22 replies
MModular
Created by gamendez98 on 2/19/2024 in #questions
How long until mojo is production ready(guesstimate)?
it's like a reverse malloc
89 replies
MModular
Created by gamendez98 on 2/19/2024 in #questions
How long until mojo is production ready(guesstimate)?
or conversely, the callback can take an integer specifying how much memory it needs to free
89 replies
MModular
Created by gamendez98 on 2/19/2024 in #questions
How long until mojo is production ready(guesstimate)?
and the callee can decide whether to continue or abort
89 replies
MModular
Created by gamendez98 on 2/19/2024 in #questions
How long until mojo is production ready(guesstimate)?
the callback can free memory and then return an integer indicating how much memory was freed
89 replies
MModular
Created by gamendez98 on 2/19/2024 in #questions
How long until mojo is production ready(guesstimate)?
That's what rethrows is
89 replies