Can anyone help me fix this code:
var ptr = alloc[List[Int]](10)
for i in range(10):
ptr.store(i, [1234])
ptr.free()
Error:
error: no matching method in call to 'store'
ptr.store(i, [1234])
~~~^~~~~~
Can anyone help me fix this code:
var ptr = alloc[List[Int]](10)
for i in range(10):
ptr.store(i, [1234])
ptr.free()
Error:
error: no matching method in call to 'store'
ptr.store(i, [1234])
~~~^~~~~~
I am getting the same error when using Mojo 0.26.2.0.dev2026021605 (eb42a2ba).
When I run this I can see the pointer already has empty lists:
fn main() raises -> None:
var ptr = alloc[List[Int]](8)
for i in range(8):
print(i, ptr[i])
So this does work:
fn main() raises -> None:
var ptr = alloc[List[Int]](8)
for i in range(8):
ptr[i].append(1234)
print(i, ptr[i])
I run this code and got core dumped. Can you help?
var s = ""
for _ in range(1000):
s += "0123456789"
var ptr = alloc[List[Int]](8)
for i in range(8):
ptr[i].append(1234)
print(i, ptr[i])
ptr.free()
On my side if I set the capacity to 25 or more I no longer get a core dumped.
fn main() raises -> None:
var s = String(capacity=25)
for _ in range(1000):
s += "0123456789"
print(len(s))
var ptr = alloc[List[Int]](8)
for i in range(8):
ptr[i].append(1234)
print(i, ptr[i])
ptr.free()
Not sure why that is though.
List manages allocation itself, so you’re accessing off the end of an array of List[Int] values.