resizeable arrays: T[new]

Walter Bright newshound1 at digitalmars.com
Mon Jun 4 14:43:52 PDT 2007


Oskar Linde wrote:
> The buffer.length = <something>; in the use case might be a neat trick, 
> but is it really that essential? Consider the rewrite: (T[] means 
> non-resizable dynamic array)
> 
> T[] foo(<parameters>, T[] buffer = null)
> {
>     T[] ret = buffer.length >= needed_capacity
>             ? buffer[0..needed_capacity]
>             : new T[needed_capacity];
>     <fill ret>
>     return ret;
> }

You're probably right with that.



More information about the Digitalmars-d-announce mailing list