Skip to content

No dynamic memory allocation at comptime #5881

Closed
@ghost

Description

Goes hand in hand with #5718. I hate hate HATE the current comptime memory management strategy. It flies in the face of everything Zig stands for. It breaks rules just for the sake of it. It requires fundamentally different logic at comptime vs runtime. It's ill-suited for applications that do heavy computations at comptime (regex, interfaces, perfect hashing etc.). #5873 proposes a better solution, and this proposal makes another thing explicit: a pointer should not be able to manage the memory it points to. So code like this should not be allowed. It requires complex logic in the compiler to detect lifetimes (a motherfreaking GARBAGE COLLECTOR for Kristoff's sake), as well as built-in reallocation logic. We invented better ways to do these things, let's not rely on unreliable solutions. Let's use the same programmer's model at comptime that we do at runtime, and only break it when we have to, not just for the sake of it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions