Hairy Pixels via fpc-pascal schrieb am
Sa., 11. Jan. 2025, 14:17:
Show quoted text 5 lines
I was curious, is there any practical limit on the size of a set (32 bits
and 256 values) and why they couldn’t be 64 bit or any other arbitrary
size? The floor seems to be 4 bytes too but why not allow smaller sizes to
save memory? Perhaps just a historical artifact but I was curious.
Set are a minimum of 4 Byte by default cause that's how Delphi does them. Ifets you want smaller sets then use the $PackSets directive as Martin had written.
The maximum is also based on what TP and Delphi allow. ISO Pascal for example suggests a maximum of 1024 elements instead, though they define this number to be implementation specific.
In the end it's a decision of where to do the cut as at some size the majority of the set will be sparsely populated so it makes more sense to use a dedicated type instead (e.g. a hash set or something like that) that wastes less memory.
Regards,
Sven