Prototype of Ownership/Borrowing System for D

Walter Bright newshound2 at
Wed Nov 20 22:23:48 UTC 2019

On 11/20/2019 10:52 AM, mipri wrote:
> How I read it is that @live doesn't know anything about malloc or
> free (except what it knows by their signatures: that malloc returns
> a pointer and that free takes ownership of a pointer).

That is correct. It only checks that the pointer value gets "consumed" exactly 
once. Passing it to another function that takes ownership of the pointer value 
counts as "consuming" it. What that function does with the pointer value is not 
the concern of the @live function.

> Where valgrind points out the use of undefined memory and the
> leaked memory. @live just cares that consume() took ownership of
> the pointer, even if consume() is not a responsible owner.
> Of course you get an error if you try to add @live to consume().
> @live isn't a superset of @safe either, since it permits the cast.

Exactly right.

More information about the Digitalmars-d mailing list