resizeable arrays: T[new]

Daniel Keep daniel.keep.lists at gmail.com
Mon Jun 4 04:50:03 PDT 2007



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

This can be pretty trivially implemented as a user type; if Walter added
implicit casts and, say, opDollar, it'd be nigh indistinguishable from
regular arrays.

Just threw up a quick and dirty version here:
http://www.prowiki.org/wiki4d/wiki.cgi?DanielKeep/snippets (bottom of
the page).

	-- Daniel



More information about the Digitalmars-d-announce mailing list