Passing dynamic arrays
Bruno Medeiros
brunodomedeiros+spam at com.gmail
Fri Nov 26 13:59:37 PST 2010
On 26/11/2010 19:16, Andrei Alexandrescu wrote:
> On 11/26/10 12:22 PM, Bruno Medeiros wrote:
>
>> But more importantly, there is a simple solution: don't write such code,
>> don't use arrays like if they are lists, preallocate instead and then
>> fill the array. So with this alternative behavior, you can still write
>> efficient code, and nearly as easily.
>
> I disagree. Often you don't know the length to preallocate (e.g. input
> is from a file etc). The fact that there's a convenient append operator
> only makes things more in favor of supporting such idioms. The technique
> (exponential capacity growth) is well known.
>
>> The only advantage of the current behavior is that it is more noob
>> friendly, which is an advantage of debatable value.
>
> I don't think the current behavior favors noobs.
>
>
> Andrei
You could still do exponential capacity growth by manipulating the
length property, but yeah, that would create a host of complexity and
other issues (see my reply to Pelle). Yeah, my reasoning was really
broken. :'(
(I need some R&R, lol)
--
Bruno Medeiros - Software Engineer
More information about the Digitalmars-d
mailing list