A question regarding Array capacity, length and slices
    Ali Çehreli via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Thu May 29 01:12:10 PDT 2014
    
    
  
On 05/29/2014 12:37 AM, Sourav wrote:
 > the behavior totally depends upon how many
 > elements were present initially in the array, which means, the capacity
 > of a slice can actually introduces little surprises in the code! Is this
 > expected behavior or am I entirely missing something here?
It is by design. I tried to explain this behavior under the section 
"Making a slice longer may terminate sharing" here:
   http://ddili.org/ders/d.en/slices.html
The section "capacity to determine whether sharing will be terminated" 
shows a way to detect whether sharing will be terminated.
Steven Schveighoffer's array article goes into design and implementation 
details:
   http://dlang.org/d-array-article.html
Ali
    
    
More information about the Digitalmars-d-learn
mailing list