Page 2 of 2 FirstFirst 12
Results 11 to 12 of 12

Thread: SetLength() out of memory :(

  1. #11

    SetLength() out of memory :(

    Quote Originally Posted by Huehnerschaender
    Code:
    for i := 0 to high(enemys) do
       if assigned(enemys[i]) then
         enemys[i].update(time_);
    Instead I would do something like:

    Code:
    for i := 0 to lastIndex do
       enemys[i].update(time_);
    Where lastIndex is not necessarily equal to high(enemys), just points to the last assigned element and the array can have any given size.

  2. #12

    SetLength() out of memory :(

    Quote Originally Posted by Huehnerschaender
    One question...
    Or does this advance you are talking about only make sense when the arrays size changes over and over again.... hundreds of times a second?

    In my case the arrays size would only change e.g. if an enemy is destroyed.
    Only when the array size changes over and over again. Using setlength once to initialize an array is not harmfull, since that compares to a simple "getmem".

    However, changing the array size when an enemy is destroyed can be harmfull and cause heap fragmentation, be it slowly.

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •