Resizable Arrays?

Jason House jason.james.house at gmail.com
Fri Feb 27 17:27:52 PST 2009


BCS Wrote:

> Reply to tim,
> 
> > Theres nothing stopping you from having all your arrays static in D. I
> > think your crazy :)
> > 
> 
> I think the thought is that arrays can have dynamic length but can't be changed 
> after allocation.

Right. Length is fixed until (re)allication.

 
> starting with:
> 
> int[] arr = new int[15];
> 
> assigning to length
> 
> arr.length = 30;
> 
> would always become
> 
> auto tmp = new int[30];
> tmp[0..min(arr.length,$)] = arr[0..min(tmp.length,$)];
> arr = tmp;

Either that or a simple compile error...

It's also possible a middle ground where only const(T)[] is fixed length until (re)allocation. I'm hoping there will be good discussion on the pros and cons of alternatives.



More information about the Digitalmars-d mailing list