I have some code that needs to create a large array. On my local computer (OSX) the program runs ok. However when I try to run the program on Ubuntu DigitalOcean droplet I get the following error:
memory allocation of 100 bytes failedAborted There isn't any other information provided in the output, but I think it has to do with initializing the vector.
fn example() { let n = 25; let mut dp: Vec<Vec<f32>> = vec![vec![-1.0; n]; 2i32.pow(n as u32) as usize]; } The size of that vector can get quite large in some instances. Is there a better way to create this large vector or is this caused by a system limit of memory?
n, what are the spec of your machine, "is this caused by a system limit of memory" obviously - -n = 25, so your inner vectors require 100 bytes each. The outer vector has length2**25, so the total size is(2**25)*100which is more than 3 gigabytes. How much memory do you have in your DO droplet?powmore readable. It could be written better though, sinceusizealso has pow:2_usize.pow(n as u32). I guess the OP following the compiler suggestion to add_i32and then was stuck with a cast.