resizeable arrays: T[new]

Lionello Lunesu lio at lunesu.remove.com
Mon Jun 4 04:49:45 PDT 2007


Manfred Nowak wrote:
> 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'

I agree. Although I'd keep the syntax less freaky by adding a property 
directly to arrays, array.capacity makes the most sense IMHO. It can be 
write-only for all I care.

Honestly, the array.length=12; array.length=0; -pattern (if you can call 
it that) is horrendous and should have been taken care of before v1.0 
was released, in my not so humble opinion.

L.



More information about the Digitalmars-d-announce mailing list