Memory Safety without a GC or Ref Counting

F i L witte2008 at gmail.com
Fri Jan 25 14:31:03 PST 2013


On Friday, 25 January 2013 at 13:14:43 UTC, TommiT wrote:
> 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).

Yeah I caught that bug after I originally posted the code as 
well. I have a solution, but it's ugly, so I'm trying to find a 
better one. Thanks for the input! I will let you know if I come 
up with anything elegant.


More information about the Digitalmars-d mailing list