Skip to content

Split realloc into separate grow and shrink methods #41

Closed
rust-lang/rust
#70362
@Amanieu

Description

@Amanieu

If you think about it, growing and shrinking an allocation are actually 2 very different operations. The only reason for merging them together is historical, because C did it.

If you look at Vec, the biggest user of realloc, you will see that growing and shrinking are two completely separate code paths. Similarly, within allocator implementations, growing and shrinking are also often handled differently.

As such, it makes sense to remove realloc and realloc_zeroed and add three new methods:

  • grow
  • grow_zeroed
  • shrink

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions