Memory Safety without a GC or Ref Counting

TommiT tommitissari at hotmail.com
Fri Jan 25 05:14:42 PST 2013


What if we re-assign a ref variable to another (or same) element 
of a DynamicArray:

var nums = int[] # DynamicArray(int)
ref foo : int

nums += 1
nums += 2

foo => nums[0] # nums.=>(0, foo)
foo = 42
foo => nums[1] # nums.=>(1, foo)

Given the definition of DynamicArray's operator =>:

func => (index, r:ref T)
{
     refs[index] += r
}

...it would mean that refs would hold two instances foo (at 
different indices).

Also, it looks like r is passed as a copy of a ref variable, 
which to me would indicate that saying r => null wouldn't nullify 
the original ref variable from which r was made a copy of (in 
this case ref variable foo).


More information about the Digitalmars-d mailing list