[fpc-pascal] bitmask vs sets. Is there a performance difference?
Graeme Geldenhuys
mailinglists at geldenhuys.co.uk
Wed Jan 20 19:26:06 CET 2016
Is there a performance difference between using bitmask values and sets?
For example:
Option #1:
=================================
const
FLAG_A = 1; // 1 shl 0
FLAG_B = 2; // 1 shl 1
FLAG_C = 4; // 1 shl 2
var
Flags: Integer;
[..]
Flags:= FLAG_A or FLAG_C;
if FLAG_A and Flags <> 0 then .. // check FLAG_A is set in flags variable
=================================
vs
Option #2:
=================================
type
TFlag = (FLAG_A, FLAG_B, FLAG_C);
TFlags = set of TFlag;
var
Flags: TFlags;
[..]
Flags:= [FLAG_A, FLAG_C];
if FLAG_A in Flags then .. // check FLAG_A is set in flags variable
=================================
While we are on the topic of Sets. What is the maximum number of values
you may have in a set, and does it differ between 32-bit and 64-bit
platforms?
Regards,
- Graeme -
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/
My public PGP key: http://tinyurl.com/graeme-pgp
More information about the fpc-pascal
mailing list