Memory allocation purity

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Wed May 14 20:18:54 PDT 2014


On Thu, 15 May 2014 01:33:34 +0000
Idan Arye via Digitalmars-d <digitalmars-d at puremagic.com> wrote:

> On Wednesday, 14 May 2014 at 22:50:10 UTC, w0rp wrote:
> > I think even C malloc should be considered pure. True, it
> > affects global state by allocating memory, but it never changes
> > existing values, it just allows for new values. free is pure
> > because it isn't side-effecting, it deallocates what you give
> > it. That's just my perspective on it though, others might have
> > other views on it.
>
> `free` is not pure, because if you have a reference to that
> memory that reference is no longer valid.

But does that really matter from the perspective of pure? That's really more
of an @safety issue. There might be some way that that violates purtiy, but I
can't think of one at the moment.

free can't be strongly pure, because it's arguments couldn't be immutable (or
even const) without violating the type system, but I _think_ that it's fine
for free to be weakly pure. It's quite possible that I'm missing something
though.

- Jonathan M Davis



More information about the Digitalmars-d mailing list