??? 06/06/07 23:50 Read: times |
#140364 - Some suggestions Bob Responding to: ???'s previous message |
You seem to go about things the long way. For example your bit set routine:
void setCacheFlag(unsigned char position){//takes position of bit to set, from 0 to 7 //this outlining section contains the cache code //always sets that bit, for simplicity unsigned char scratch=0x80; unsigned char i=0x00; if(position>=8){ while((position-=8)>8){ i++; } } scratch>>=position;//put bit into proper position cacheUsed[i]|=scratch;//set that bit in the used flag } From what I can understand you have an array of bits and you want to set a particular bit in that array. To that end: const char bit_masks[]={1,2,4,8,16,32,64,128}; void setCacheFlag(unsigned char position)//takes position of bit to set, from 0 to 7 { cacheUsed[position>>3] |= bit_masks[position & 0x07]; } Here we've used the fact that there's 8 bits per byte and shifting right by 3 bits does a division by 8. For non binary numbers we could use division and the modulus operator: cacheUsed[position/8] |= bit_masks[position % 8]; We've avoided using loops and (hopefully) the code is a bit more obvious. |
Topic | Author | Date |
Software design problem | 01/01/70 00:00 | |
Something like this, maybe? | 01/01/70 00:00 | |
Well, yes, actually... | 01/01/70 00:00 | |
Duhr and a question | 01/01/70 00:00 | |
Which ones did you look at ? | 01/01/70 00:00 | |
Duhr and an answer | 01/01/70 00:00 | |
Is it not possible to | 01/01/70 00:00 | |
Horses for courses | 01/01/70 00:00 | |
have fun | 01/01/70 00:00 | |
A Queue? | 01/01/70 00:00 | |
I used what I called a \'cache\' | 01/01/70 00:00 | |
Gah, code repost | 01/01/70 00:00 | |
you need to read it all, THEN process | 01/01/70 00:00 | |
Your approach is much more general... | 01/01/70 00:00 | |
Prioritizing? | 01/01/70 00:00 | |
Some suggestions Bob | 01/01/70 00:00 | |
Thank you, sir! | 01/01/70 00:00 | |
Division / modulus not always slow | 01/01/70 00:00 | |
Are we making this too difficult? | 01/01/70 00:00 | |
I don't think so, it seems to work pretty well...![]() | 01/01/70 00:00 |