deep copy or shallow copy?

Jonathan M Davis jmdavisProg at gmx.com
Fri Dec 9 13:18:02 PST 2011


On Friday, December 09, 2011 22:09:15 Timon Gehr wrote:
> On 12/09/2011 09:32 PM, Ali Çehreli wrote:
> > So it is impossible to do anything shallow with them unless we
> > explicitly maintain a pointer to a fixed-length array ourselves.
> > 
> > Ali
> 
> You can always slice it, of course
> 
> int[3] a;
> int[] b = a[]; // b now is a dynamic array that aliases a's contents

Though, of course, you have to be careful with that, since the static array 
then owns the memory for that dynamic array, and if the static array goes out 
of scope before the dynamic array does, then the dynamic array points to 
garbage and will result in bugs.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list