|
![](/i/fill.gif) |
Warp wrote:
> Jim Charter <jrc### [at] msn com> wrote:
>> In arrays.inc there is a macro to resize an array. So you can define
>> you array initially to take the first item then resize it with each
>> sucessful read from your file.
>
> This is not a good solution, especially if the amount of items is large.
>
> The resizing is done by creating a second array of the new size and
> then copying the elements of the first array into the second. If you do
> this for all n elements in the input you'll end up doing n resizes and
> n+(n-1)+(n-2)+...+1 copy operations, which grows proportional to the
> square of n. (For example if the input had 1000 elements it would end up
> making 500500 copy operations. That's half million.)
>
but what you can do, is start out with a reasonable guess and increase
it from there (by jumps). You may end up wasting some space by growing
the array too large, but it would work.
-ds
Post a reply to this message
|
![](/i/fill.gif) |