Booleans vs sets

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Booleans vs sets

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

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Booleans vs sets

Mattias Gaertner
On Thu, 21 Sep 2017 15:16:21 +0700
Ryan Joseph <[hidden email]> 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.

Mattias
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Booleans vs sets

Michael Van Canneyt


On Thu, 21 Sep 2017, Mattias Gaertner wrote:

> On Thu, 21 Sep 2017 15:16:21 +0700
> Ryan Joseph <[hidden email]> 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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Booleans vs sets

Ryan Joseph
Got it, thanks guys.

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

> On Sep 21, 2017, at 4:47 PM, Michael Van Canneyt <[hidden email]> wrote:
>
>
>
> On Thu, 21 Sep 2017, Mattias Gaertner wrote:
>
>> On Thu, 21 Sep 2017 15:16:21 +0700
>> Ryan Joseph <[hidden email]> 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  -  [hidden email]
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Booleans vs sets

Free Pascal - General mailing list

Am 22.09.2017 12:56 schrieb "Ryan Joseph" <[hidden email]>:
>
> 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


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal