Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
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.



List of 25 messages in thread
TopicAuthorDate
how to use buffer or stack to store digits            01/01/70 00:00      
   many question            01/01/70 00:00      
   Stack            01/01/70 00:00      
   use register as a pointer to a table            01/01/70 00:00      
      How many segments?            01/01/70 00:00      
         you seldom need to use both ...            01/01/70 00:00      
            Not as DP, but...            01/01/70 00:00      
               sorry ... double post            01/01/70 00:00      
               Why would you want those?            01/01/70 00:00      
                  example            01/01/70 00:00      
      Timer interrupt and segments in RAM            01/01/70 00:00      
         many words about two lousy microseconds            01/01/70 00:00      
            Lousy microseconds            01/01/70 00:00      
               Wholehardely agree            01/01/70 00:00      
                  Burning stack bytes            01/01/70 00:00      
                     you need to read "the bible"            01/01/70 00:00      
                        Not entirely true            01/01/70 00:00      
                     Table lookup in 'C'            01/01/70 00:00      
                        Why tables can be costly on C            01/01/70 00:00      
                           Well, If you abuse the tools...            01/01/70 00:00      
                           if we consider this off topic, you may be correct            01/01/70 00:00      
                              Not even then?            01/01/70 00:00      
                                 Another thread, please            01/01/70 00:00      
                                    And the new thread is...            01/01/70 00:00      
   Example on driving 7-segment displays            01/01/70 00:00      

Back to Subject List