Results 1 to 7 of 7

Thread: Setting a whole bool-array to FALSE

  1. #1

    Setting a whole bool-array to FALSE

    Hi fellow-c0ders

    i've got a short question. Does anyone know a trick how to set an entire bool-array to false.
    I usually did this with a loop, but it just doesn't feel good. I need this quite often for initialization.

    Anyone?

    Thanx
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  2. #2

    Setting a whole bool-array to FALSE

    Code:
    var
      a: array [0..5] of boolean;
    begin
      fillchar(a, length(a)*sizeof(boolean), 0);
    end.
    This, of course, works with dynamic arrays as well.

    It might also be faster than your for-method since I guess fillchar deals
    with the array as whole chunk of memory. So the code gets rid off
    the jumps, comparisons and assignments a for loop needs.

  3. #3

    Setting a whole bool-array to FALSE

    great, i'm often using loops for it
    From brazil (:

    Pascal pownz!

  4. #4

    Setting a whole bool-array to FALSE

    Ok, I tried now.

    Its indeed faster than a loop. The bigger the array is, the faster
    fillchar gets compared to a loop.


    edit: added a comma ^^

  5. #5

    Setting a whole bool-array to FALSE

    Quote Originally Posted by waran
    Ok, I tried now.

    Its indeed faster than a loop. The bigger the array is the faster
    fillchar gets compared to a loop.
    sorry for my english, its faster or slower or equal performance?
    From brazil (:

    Pascal pownz!

  6. #6

    Setting a whole bool-array to FALSE

    Okay... i think he means this:

    When using very big array's, fillchar can give a great performance boost.
    When using smaller array's, the performance boost is less, when compared to the FOR loop.

    I must say that the sentence is a litlle hard to understand, because of the absence of punctuation.

    Hope you understand
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  7. #7

    Setting a whole bool-array to FALSE

    thanks, so i will use it
    From brazil (:

    Pascal pownz!

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
  •