Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:15 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : CM2: DIM bit

     Page 1 of 4    
Author Message
bar1010
Senior Member

Joined: 10/08/2020
Location: United States
Posts: 197
Posted: 05:09pm 18 Sep 2020
Copy link to clipboard 
Print this post

Wouldn’t it be nice if we had DIM bit functionality to minimize the amount of storage needed
for a variable with two values?
It would require eight times less space than a string with length 1.
Edited 2020-09-19 03:32 by bar1010
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3378
Posted: 05:30pm 18 Sep 2020
Copy link to clipboard 
Print this post

I think the question will be "How many more than 512K bytes do you need?"
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 05:49pm 18 Sep 2020
Copy link to clipboard 
Print this post

Hi bar0101,

IMHO the best (only?) way to implement such functionality would be to use integers and a bunch of Functions or CSubs (better CFunctions if they existed). I did something similar in my Game Of Life ... but not consistently (because I upgraded an existing program).
Good luck!

Michael
causality ≠ correlation ≠ coincidence
 
RetroJoe

Senior Member

Joined: 06/08/2020
Location: Canada
Posts: 290
Posted: 05:49pm 18 Sep 2020
Copy link to clipboard 
Print this post

  lizby said  I think the question will be "How many more than 512K bytes do you need?"


Well, as we know from Bill Gates, no-one will ever need more than 640K  
Edited 2020-09-19 03:51 by jpusztai
Enjoy Every Sandwich / Joe P.
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3378
Posted: 05:56pm 18 Sep 2020
Copy link to clipboard 
Print this post

  twofingers said  IMHO the best (only?) way to implement such functionality would be to use integers and a bunch of Functions or CSubs (better CFunctions if they existed).


CaptainBoing is ahead of us with that: bit manipulation
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 06:11pm 18 Sep 2020
Copy link to clipboard 
Print this post

  lizby said  I think the question will be "How many more than 512K bytes do you need?"

sounds like:
  Quote  640 kB ought to be enough for anybody. (maybe Bill Gates?)


@lizby
Sometimes you have to handle more than 512KB of data and a smaller amount of data is generally faster to copy, manipulate, move, and store.

Kind regards
Michael

EDIT. jpusztai was faster (640KB).  

@lizby: Thanks for the bit manipulation link!
Edited 2020-09-19 04:15 by twofingers
causality ≠ correlation ≠ coincidence
 
RetroJoe

Senior Member

Joined: 06/08/2020
Location: Canada
Posts: 290
Posted: 06:12pm 18 Sep 2020
Copy link to clipboard 
Print this post

Cool!

I am using events in my project (an arcade game with things like “IF event.fire = 1”), so can someone opine on the “speed vs storage” using the Captain’s FLAGS method? I anticipate I will need to manage 30 or so events, and it seems the setting and getting of FLAG bits is slower than comparing actual variables, but I could be wrong.

P.S. I sense an MMBasic enhancement request for Boolean variables in 3, 2, 1...
Enjoy Every Sandwich / Joe P.
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 06:28pm 18 Sep 2020
Copy link to clipboard 
Print this post

@Joe

I would use integers as flags with the current MMBasic version. At least if you want to check only individual flags, no sets of flags with a bit pattern mask
causality ≠ correlation ≠ coincidence
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 06:43pm 18 Sep 2020
Copy link to clipboard 
Print this post

You have 5 MB or variable memory (512K of program memory), so I wouldn't be prematurely optimising for size. Performance wise I definitely wouldn't be bit twiddling in your main loop if you have an alternative.

Best wishes,

Tom
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3378
Posted: 06:48pm 18 Sep 2020
Copy link to clipboard 
Print this post

  twofingers said  Sometimes you have to handle more than 512KB of data and a smaller amount of data is generally faster to copy, manipulate, move, and store.

And you have enough hundreds of flags for it to make a difference? I'm just wondering about a use case for the CMM2.

I believe in another thread CaptainBoing said that his experimentation had determined that the bit manipulation routines were slower than just using integers, but it hurt his sense of efficiency to be "wasting" all those bits.

Having started in a time when programmers were cheap ($5 an hour for my first full-time job) and computers were expensive ($100 a minute), I can't say how many "efficiencies" I've given up as the price per cycle and per bit has plummeted.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
bar1010
Senior Member

Joined: 10/08/2020
Location: United States
Posts: 197
Posted: 07:14pm 18 Sep 2020
Copy link to clipboard 
Print this post

  lizby said  
  twofingers said  Sometimes you have to handle more than 512KB of data and a smaller amount of data is generally faster to copy, manipulate, move, and store.

And you have enough hundreds of flags for it to make a difference? I'm just wondering about a use case for the CMM2.

I believe in another thread CaptainBoing said that his experimentation had determined that the bit manipulation routines were slower than just using integers, but it hurt his sense of efficiency to be "wasting" all those bits.

Having started in a time when programmers were cheap ($5 an hour for my first full-time job) and computers were expensive ($100 a minute), I can't say how many "efficiencies" I've given up as the price per cycle and per bit has plummeted.


I had in mind using a multi-dimensional array of bits.  For example, a binary image.
Edited 2020-09-19 05:19 by bar1010
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 07:32pm 18 Sep 2020
Copy link to clipboard 
Print this post

  lizby said  
  twofingers said  Sometimes you have to handle more than 512KB of data and a smaller amount of data is generally faster to copy, manipulate, move, and store.

And you have enough hundreds of flags for it to make a difference? I'm just wondering about a use case for the CMM2.

Note: I never said it would be a solution for flags!
  twofingers said  @Joe

I would use integers as flags with the current MMBasic version. At least if you want to check only individual flags, no sets of flags with a bit pattern mask


BTW. CaptainBoings functions are not the optimum.
Faster than (bit set)
a=a or (2^63)

is this
a=a or (1<<63)

Faster than (bit reset)
a=(a OR (2^63)) XOR (2^63)

is this
a=a AND inv (1<<63)


Maybe CaptainBoing can update the Wiki?

Regards
Michael
causality ≠ correlation ≠ coincidence
 
bar1010
Senior Member

Joined: 10/08/2020
Location: United States
Posts: 197
Posted: 07:37pm 18 Sep 2020
Copy link to clipboard 
Print this post

  thwill said  You have 5 MB or variable memory (512K of program memory), so I wouldn't be prematurely optimising for size. Performance wise I definitely wouldn't be bit twiddling in your main loop if you have an alternative.

Best wishes,

Tom

If we have 5 MB of variable memory, why do I receive Error: Not enough heap memory
with the statement dim string test$(137,137,137) length 1?  Shouldn’t this allocation require
2,571,353 bytes and thereby fit within 5MB?
 
RetroJoe

Senior Member

Joined: 06/08/2020
Location: Canada
Posts: 290
Posted: 07:40pm 18 Sep 2020
Copy link to clipboard 
Print this post

Thanks, guys, for confirming - I will stick with honest-to-goodness variables, but having grown up in a “memory is scarce” era, I guess we all have the same guilt pangs of wasteful storage. The overhead of any compression scheme is quite significant, and I certainly will not be needing it. I also like the idea that a “bit is a bit” I.e. there is a degree of code validation if a logical Boolean value is guaranteed to have only one of two states I.e. preventing coding, coercion or rounding that makes 1 not quite equal to 1.

FYI, I just worked on a project where we had to provision 8 TB, with a “tee”, of RAM on a server. I’m thinking that much RAM did not exist on the entire planet until quite recently :) Initially, I kept writing “8 GB” in my emails until I got the exponent value right :)

And, regarding scarce resources and the inversion of labour to hardware costs, check out this video on the fabrication of the “rope memory” (ROM) used in the AGC (Apollo Guidance Computer). Forget about the costs - can you imagine working on a project like this, where the “build” takes months, and debugging is a nightmare?? I thought burning and UV erasing EPROMs was a tedious process...  but this is insane!

If you’re interested, there is a multipart YT of a team of computer historian fanatics that have restored an AGC to working order, including recreating the development tool chain, writing emulators for the AGC, and OCRing the archived printout of source code - amazing stuff.
Enjoy Every Sandwich / Joe P.
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 07:44pm 18 Sep 2020
Copy link to clipboard 
Print this post

  bar1010 said  If we have 5 MB of variable memory, why do I receive Error: Not enough heap memory with the statement dim string test$(137,137,137) length 1?  Shouldn’t this allocation require  2,571,353 bytes and thereby fit within 5MB?

Each of your strings uses 2 bytes (length byte + 1).
causality ≠ correlation ≠ coincidence
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3378
Posted: 07:50pm 18 Sep 2020
Copy link to clipboard 
Print this post

  twofingers said  Note: I never said it would be a solution for flags!

Fair enough. What is the use case?
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 07:51pm 18 Sep 2020
Copy link to clipboard 
Print this post

  jpusztai said  [...] but having grown up in a “memory is scarce” era, I guess we all have the same guilt pangs of wasteful storage. [...]

I think that's true for many here.
causality ≠ correlation ≠ coincidence
 
bar1010
Senior Member

Joined: 10/08/2020
Location: United States
Posts: 197
Posted: 07:54pm 18 Sep 2020
Copy link to clipboard 
Print this post

  lizby said  
  twofingers said  Note: I never said it would be a solution for flags!

Fair enough. What is the use case?

Binary images
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4044
Posted: 07:58pm 18 Sep 2020
Copy link to clipboard 
Print this post

  jpusztai said  I also like the idea that a “bit is a bit” I.e. there is a degree of code validation if a logical Boolean value is guaranteed to have only one of two states I.e. preventing coding, coercion or rounding that makes 1 not quite equal to 1.

Then use some functions to make it so.

They'll run much slower than using inline code of course, but that's a normal speed/size tradeoff.

John
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3378
Posted: 08:02pm 18 Sep 2020
Copy link to clipboard 
Print this post

  bar1010 said  
  lizby said  
  twofingers said  Note: I never said it would be a solution for flags!

Fair enough. What is the use case?

Binary images

I'd need more elaboration to understand what needs to be done with these binary images that cannot now effectively be done (and the necessary time scale).
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
     Page 1 of 4    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025