12-19-2022, 09:05 PM
@Pete Where _TOGGLEBIT can be useful is when you're bitpacking data to save memory usage. As an old skool programmer (tm), you should be aware of the concept, even if you never used it.
Let's say you're writing a program and TRULY need to preserve memory usage. Maybe it's got a 10,000,000 record database for customer information associated with it -- THAT could warrant some aggressive memory management!
Now, let's say they have a bunch of boolean data:
HasPhone
AllowsCalls
HasEmail
AllowsEmails
HasPhysicalMail
AllowsPhysicalMail
HasSex
WithPete
Now, you could use 8 variables and store those for a good 100+ bytes of memory usage with each record..
OR...
You could store it all on one byte, but reserving a bit for each value in a single character.
If the user has a phone then UserCompressedData = _ToggleBit(UCD, 1).
The phone breaks: UCD = _ToggleBit(UCD, 1)
Has email? Togglebit 3.
Loses their password and can't log in? Togglebit 3.
On/Off toggles stored in bits in a character. <- that's what it's for.
Let's say you're writing a program and TRULY need to preserve memory usage. Maybe it's got a 10,000,000 record database for customer information associated with it -- THAT could warrant some aggressive memory management!
Now, let's say they have a bunch of boolean data:
HasPhone
AllowsCalls
HasEmail
AllowsEmails
HasPhysicalMail
AllowsPhysicalMail
HasSex
WithPete
Now, you could use 8 variables and store those for a good 100+ bytes of memory usage with each record..
OR...
You could store it all on one byte, but reserving a bit for each value in a single character.
If the user has a phone then UserCompressedData = _ToggleBit(UCD, 1).
The phone breaks: UCD = _ToggleBit(UCD, 1)
Has email? Togglebit 3.
Loses their password and can't log in? Togglebit 3.
On/Off toggles stored in bits in a character. <- that's what it's for.