Is this a bug?

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Apr 29 09:52:26 PDT 2014


On 04/29/2014 01:36 AM, John Colvin wrote:

 > D dynamic arrays (better referred to as slices) can be thought of as
 > implmented like
 >
 > struct Array(T)
 > {
 >      T* ptr;
 >      size_t length;
 > }
 >
 > They do not track ownership or have any reference counting. If they've
 > been allocated with "new" then the GC will take care of them once there
 > are no remaining references to them.

That may be misleading because there is no need to allocate with an 
explicit new. For example, the slice below is owned by the GC as well:

int[] foo()
{
     int[] a;
     a ~= 42;    // on memory owned by the GC
     return a;
}

Ali



More information about the Digitalmars-d-learn mailing list