Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2017-09

Booleans vs sets

5 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Ryan Joseph

I have a class that is filling up with booleans. Would it be more efficient to store these as a “set of”? I have 10 bools which is getting up there.

Regards,
Ryan Joseph

Reply by email

Mattias Gaertner
to Ryan Joseph
I have a class that is filling up with booleans. Would it be more efficient to store these as a “set of”? I have 10 bools which is getting up there.

Sets need less memory as they are stored as bits.
Speed depends on the operations and amount of objects. I would recommend sets.

Mattias

Reply by email

Michael Van Canneyt
to Mattias Gaertner
Mattias Gaertner wrote 8 lines
On Thu, 21 Sep 2017 15:16:21 +0700 Ryan Joseph wrote: > I have a class that is filling up with booleans. Would it be more efficient to store these as a “set of”? I have 10 bools which is getting up there. Sets need less memory as they are stored as bits. Speed depends on the operations and amount of objects. I would recommend sets.

Same here.

Michael.

Reply by email

Ryan Joseph
to Michael Van Canneyt

Got it, thanks guys.

Btw, how can I know what the size in bytes these 2 options are?

Show quoted text 20 lines
On Sep 21, 2017, at 4:47 PM, Michael Van Canneyt wrote: On Thu, 21 Sep 2017, Mattias Gaertner wrote: > On Thu, 21 Sep 2017 15:16:21 +0700 > Ryan Joseph wrote: > >> I have a class that is filling up with booleans. Would it be more efficient to store these as a “set of”? I have 10 bools which is getting up there. > > Sets need less memory as they are stored as bits. > Speed depends on the operations and amount of objects. > I would recommend sets. Same here. Michael._______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Regards,
Ryan Joseph

Reply by email

Sven Barth
to Ryan Joseph
"Ryan Joseph" wrote
Got it, thanks guys. Btw, how can I know what the size in bytes these 2 options are?

You could use SizeOf(YourType) and output the values in a simple test program :)

Regards,
Sven

Reply by email