DAY 040: _TOGGLEBIT
#4
@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.  Smile
Reply


Messages In This Thread
DAY 040: _TOGGLEBIT - by Pete - 12-19-2022, 07:43 PM
RE: DAY 040: _TOGGLEBIT - by mnrvovrfc - 12-19-2022, 08:32 PM
RE: DAY 040: _TOGGLEBIT - by SMcNeill - 12-19-2022, 08:43 PM
RE: DAY 040: _TOGGLEBIT - by mnrvovrfc - 12-19-2022, 09:37 PM
RE: DAY 040: _TOGGLEBIT - by SMcNeill - 12-19-2022, 09:05 PM
RE: DAY 040: _TOGGLEBIT - by Pete - 12-19-2022, 09:17 PM
RE: DAY 040: _TOGGLEBIT - by SMcNeill - 12-19-2022, 09:47 PM
RE: DAY 040: _TOGGLEBIT - by Pete - 12-19-2022, 10:03 PM
RE: DAY 040: _TOGGLEBIT - by SMcNeill - 12-19-2022, 10:22 PM
RE: DAY 040: _TOGGLEBIT - by Pete - 12-19-2022, 10:30 PM
RE: DAY 040: _TOGGLEBIT - by SMcNeill - 12-19-2022, 10:42 PM
RE: DAY 040: _TOGGLEBIT - by bplus - 12-19-2022, 11:20 PM
RE: DAY 040: _TOGGLEBIT - by Pete - 12-19-2022, 11:22 PM
RE: DAY 040: _TOGGLEBIT - by Jack - 12-19-2022, 11:58 PM
RE: DAY 040: _TOGGLEBIT - by Pete - 12-20-2022, 01:11 AM
RE: DAY 040: _TOGGLEBIT - by vince - 12-20-2022, 01:59 AM
RE: DAY 040: _TOGGLEBIT - by OldMoses - 12-20-2022, 03:46 AM



Users browsing this thread: 14 Guest(s)