resizeable arrays: T[new]

Manfred Nowak svv1999 at hotmail.com
Mon Jun 4 03:14:58 PDT 2007


Walter Bright wrote

> The attractiveness of this 
> solution is it nearly completely solves the problem with zero
> runtime cost. 

Great thought.
If incorporating this new type, please address also the complication 
of having two views on the storage allocated for resizable arrays:
- the "potential" capacity, to which the `length' property currently 
can grow without the need of allocating more consecutive space
- the "actual" capacity, which is currently set/get by the `length' 
property

It is a pity, that the documentation, 
http://www.digitalmars.com/d/arrays.html#resize,
illustrates a pattern that can be easily incorporated into the 
language as a default behaviour:
- introduce new `length.pot' r/w-property
- whenever the `length' property exceeds the `length.pot' property 
double the `length.pot' property and allocate appropriate space
- issue an error when `length.pot' is decreased below the value of 
`length'
 
-manfred



More information about the Digitalmars-d-announce mailing list