C++/C has a lot of "features" which seem tantalizing at first; but end up being against the point of a systems language.
Putting large arrays on the heap (not sure if C++ does this, but it sounds like something C++ would do) is one -- there are plenty of cases where you explicitly want stack-based arrays in systems programming. Another is the alloca-like behavior of dynamically sized stack-based arrays (just learned about this recently). You always want to be clear of what the compiler is doing. Such optimizations can easily be implemented as a library :) -Manish Goregaokar On Thu, Nov 27, 2014 at 10:20 PM, Diggory Hardy <li...@dhardy.name> wrote: > 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 <benwilson...@gmail.com> > 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 > > #[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 > Rust-dev@mozilla.org > https://mail.mozilla.org/listinfo/rust-dev > > > > > _______________________________________________ > Rust-dev mailing list > Rust-dev@mozilla.org > https://mail.mozilla.org/listinfo/rust-dev > >
_______________________________________________ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev