View Full Version : Setting a whole bool-array to FALSE
chronozphere
12-12-2007, 03:41 PM
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 :)
waran
12-12-2007, 03:58 PM
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.
arthurprs
12-12-2007, 04:02 PM
great, i'm often using loops for it :)
waran
12-12-2007, 04:09 PM
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 ^^
arthurprs
12-12-2007, 04:34 PM
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?
chronozphere
12-12-2007, 05:21 PM
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 ;)
arthurprs
12-12-2007, 05:39 PM
thanks, so i will use it :D
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.