POV-Ray : Newsgroups : povray.programming : Growing arrays : Re: Growing arrays Server Time
28 Jul 2024 14:23:42 EDT (-0400)
  Re: Growing arrays  
From: Warp
Date: 29 Sep 2000 11:46:33
Message: <39d4b958@news.povray.org>
Disnel <dis### [at] itamcascz> wrote:
: If we assume, that array can only grow, thinkgs become simplier.

  Actually it's the opposite: If we assume that an array can only shrink
(ie. get smaller) then the answer is very trivial (unless you really want
to _free_ that non-used memory as well).
  If it has to be possible to grow the array, some specialized algorithm
has to be implemented. You can't make the array bigger every time the
user wants to make it one item bigger because it would be extremely slow
(specially with big arrays) but you have to reserve space for more than
one item at a time. When the array gets full you have to reserve a bigger
array and copy the old one there (and then free the old one). This copying
is the heaviest operation in the dynamic array and shouldn't be done
too often.

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.