Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Space Limit--What is expendable? (http://www.chiefdelphi.com/forums/showthread.php?t=22810)

ErichKeane 02-12-2003 14:37

Re: Space Limit--What is expendable?
 
Quote:

Originally Posted by Dave Flowerday
Actually it'd be better to use this:
Code:

signedpwm01 = (char) pwm01 - 128;
A signed char can range from -128 to 127. Thus, if you subtract 128 it will give you a reasonable value for any value of pwm01. If you subtract 127, then you get into a problem if pwm01 = 255. 255-127 = 128, however a signed char cannot be 128, and will actually end up being -128! (This is a side effect of the way a computer stores a negative number). Realistically, pwm01 isn't supposed to be larger than 254, but in software it's usually better to make something work for all cases rather than assume that certain cases won't occur.


Ah, correct on that one. The reason i put -127 is it correctly centers it every time, and i have a cleaning function run that basically limits the pwm values before hand, so 254 is the max necessary. The other thing you could do would be to use INT's, which allows a large amount more of integer mathematics, another thing my team found necessary.

josh_johnson 02-12-2003 17:01

Re: Space Limit--What is expendable?
 
Quote:

Originally Posted by Anthony Kesich
On that note, does anybody know if you can nest the ?: operator? i.e. x=(condtion 1) ? 1 : (condition 2) ? 2 : (condition 3) ? 3 : ... (condition n) ? n : 0

yes, you can nest the ?: operator, although i am not certain of the order of operations so you might want to type it like

x=(condition1 ? 1 : (condition2 ? 2 : (condition3 ? 3 : ...(condition n ? n : 0)...))

also a range of case statements cannot be used as in PBasic however the following is a way to simulate this.


switch(statement) {
case 1:
case 2:
case 3:
doSomething();
break;
case 4:
case 5:
case 6:
doSomethingElse();
break;
}


However this would not be practical for a very large range of values.

Also, if the compiler compiles the sane way as the C compiler I have studied, a switch/case statement uses up more code space than if/else statements, especially when there is a large range of skipped values such as. ..


switch(statement) {
case 1:
doSomething();
break;
case 1000000:
doSomethingElse();
break;
}


Switch/case statements are quicker than several if/else statements though because it jumps to a calculated address rather than having to make many comparisons, but this will not be noticeable if there are only a few choices.

Rickertsen2 04-12-2003 16:44

Re: Space Limit--What is expendable?
 
Quote:

Originally Posted by Random Dude
Whats wrong with signed chars? I've converted all my PWM signals to signed to simplify the math.

I have done the same. The reason i specified unsigned chars is bc they take more instructions to process. This translates into larger programs and slower execution times. If you arn't having problems with speed and or space i wouldn't worry about it. If you want to demonstrate this for yourself, write a program that does some signed and unsigned operations, and then look at the assembly code.

ErichKeane 06-12-2003 21:37

Re: Space Limit--What is expendable?
 
Quote:

Originally Posted by Rickertsen2
I have done the same. The reason i specified unsigned chars is bc they take more instructions to process. This translates into larger programs and slower execution times. If you arn't having problems with speed and or space i wouldn't worry about it. If you want to demonstrate this for yourself, write a program that does some signed and unsigned operations, and then look at the assembly code.

Technically yes, you are correct, the difference between signed and unsigned mathematics is a little more processor intensive. It does not take more space though in the memory banks at all afaik. I believe all it does is use an unsigned Char, and then subtract the 127/128 or whatever in implementaiton. The difference is so minimal between the two, i never saw it as a problem.

I did a few things that helped me save a huge amount of space.
1- I reverted to completely integer mathematics, as opposed to floating point mathematics, which are horrid!
2- got rid of all unnecessary portions of the default code. That removed a large amount of the space (about 12% of our programming memory!), and left a good amount of the programming to me instead of some default setup.
3- Got rid of that printf library. It is easily the worst written print library i have seen in ages. Instead, my team is using the printword and printbyte and etc library in the utilities.

You guys have been a great help, keep the good posts comming.

Mark McLeod 08-12-2003 18:56

Re: Space Limit--What is expendable?
 
The IFI_Loader will also give you the space used.
Just hit return when IFI_Loader is active and you'll get a report in the bottom message bar.


All times are GMT -5. The time now is 19:51.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi