Shouldn't the compiler automatically put large arrays on the heap? I thought 
this was a common 
thing to do beyond a certain memory size.

On Thursday 27 November 2014 04:28:03 Steven Fackler wrote:


The `nums` array is allocated on the stack and is 8 MB (assuming you're on a 64 
bit platform).



On Wed Nov 26 2014 at 8:23:08 PM Ben Wilson <[email protected][1]> wrote:


Hey folks, I've started writing some rust code lately and run into weird 
behavior when benchmarking. 
When running


https://gist.github.com/benwilson512/56f84ffffd4625f11feb[2]

#[bench]
fn test_overflow(b: &mut Bencher) {
  let nums = [0i, ..1000000];
  b.iter(|| {
    let mut x = 0i;
    for i in range(0, nums.len()) {
      x = nums[i];
    }
  });
}


 I get "task '<main>' has overflowed its stack" pretty much immediately when 
running cargo bench. 
Ordinarily I'd expect to see that error when doing recursion, but I can't quite 
figure out why it's 
showing up here. What am I missing?



Thanks!


- Ben
_______________________________________________Rust-dev mailing list

[email protected][3]
https://mail.mozilla.org/listinfo/rust-dev[4]




--------
[1] mailto:[email protected]
[2] https://gist.github.com/benwilson512/56f84ffffd4625f11feb
[3] mailto:[email protected]
[4] https://mail.mozilla.org/listinfo/rust-dev
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to