Skip to content

The Vec should not needlessly overallocate capacity if it is guaranteed to fail. #31446

Open
@ghost

Description

Current Vec / RawVec allocation strategy is to at least double the capacity on
reallocation. This leads to unnecessary panic when the new overallocated
capacity exceeds std::isize::MAX. If allocating std::isize::MAX would be
sufficient it should do so instead.

For example I would expect the following to work on 32-bit platform (provided
that there is sufficient amount of memory):

fn main() {
    let mut v = std::vec::from_elem(1 as u8, (std::isize::MAX / 2 + 1) as usize);
    v.push(1);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-collectionsArea: `std::collections`C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions