Skip to content

placing large array inside Box causes stack overflow #28008

Closed
@XAMPPRocky

Description

@XAMPPRocky

I was trying to store a large array on the heap, the code produced a run-time error of stack overflow.

fn main() {
    let x = Box::new([0; 10_000_000]);
}

I expected the array to be initialised on the heap.

Instead it seems, the array is being initialised onto the stack, and then placed onto the heap, causing the this error message. thread '<main>' has overflowed its stack.

Meta

rustc --version --verbose:

rustc 1.2.0 (082e47636 2015-08-03)
binary: rustc
commit-hash: 082e4763615bdbe7b4dd3dfd6fc2210b7773edf5
commit-date: 2015-08-03
host: x86_64-apple-darwin
release: 1.2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions