back to arays

Regan Heath regan at netwin.co.nz
Mon May 15 00:39:06 PDT 2006


On Mon, 15 May 2006 10:05:22 +0300, Max Samuha <maxter at i.com.ua_spamless>  
wrote:
> I thought array references are similar to object references like in C#
> (actually, thay are object references in C#) and that was my mistake:
>
> int[] a = new int[20];
> int[] b = a;
>
> a.length = 40; // a is copied and b is not updated to point to a's
> data;
>
> Does it mean that anytime i change an array, i have to manually update
> all references to it or should i wrap my array in an Array class so
> that all references to any instance of that array remain valid?
>
> If the question have been already discussed please refer me to the
> right thread. Thanks

The D philosophy is "copy on write". Whenever you have several references  
to the same data and you decide to write to the data, you should make a  
copy and write to the copy. If you want to constantly have several  
references to the same data then yes, you will have to update the  
references whenever you make change or write a class to handle that for  
you.

Regan



More information about the Digitalmars-d-learn mailing list