![]() |
Forum Index : Microcontroller and PC projects : CM2: DIM bit
Page 1 of 4 ![]() ![]() |
|||||
Author | Message | ||||
bar1010 Senior Member ![]() Joined: 10/08/2020 Location: United StatesPosts: 197 |
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 StatesPosts: 3378 |
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: GermanyPosts: 1593 |
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: CanadaPosts: 290 |
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 StatesPosts: 3378 |
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: GermanyPosts: 1593 |
sounds like: ![]() @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: CanadaPosts: 290 |
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: GermanyPosts: 1593 |
@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 KingdomPosts: 4311 |
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 StatesPosts: 3378 |
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 StatesPosts: 197 |
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: GermanyPosts: 1593 |
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! 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 StatesPosts: 197 |
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: CanadaPosts: 290 |
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: GermanyPosts: 1593 |
Each of your strings uses 2 bytes (length byte + 1). causality ≠correlation ≠coincidence |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3378 |
Fair enough. What is the use case? PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
twofingers![]() Guru ![]() Joined: 02/06/2014 Location: GermanyPosts: 1593 |
I think that's true for many here. ![]() causality ≠correlation ≠coincidence |
||||
bar1010 Senior Member ![]() Joined: 10/08/2020 Location: United StatesPosts: 197 |
Fair enough. What is the use case? Binary images |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 4044 |
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 StatesPosts: 3378 |
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 ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |