| ??? 12/03/07 09:01 Read: times |
#147765 - Why tables can be costly on C Responding to: ???'s previous message |
There are actually several reasons why lookup tables can be costly in C - especially in embedded C.
One major mistake is to believe that the table is in ROM (Flash). By C definition such tables go into RAM if not told to do so. It is easy to forget to put the special keywords (depending on compiler) to make the constants be stored into ROM. The values themselves are of course stored in ROM but during the POR the reset code in CRT0 will copy them in place. I did spend numerous hours trying to figure out why I was running out of memory with ordinary strings like "This Is a String"... Another reason is the fact that when the C compiler creates the lookup code it may not be efficient. This also depends on the compiler and also on the target MCU. I have seen assembly generated by a compiler that had a multiply on each lookup access. That was of course a tad more complex lookup with structures and all. |



