3 Replies Latest reply on Jan 4, 2013 11:32 AM by user_1377889

    Global vs Static Variables

    user_14586677

      Continuing discussion on variable usage. Attached.

         

       

         

      Regards, Dana.

        • 1. Re: Global vs Static Variables
          user_1377889

          The linked document concerning performance of local variables does not take into account that we here with PSoCs have different architectures. Take the PSoC3 where we have a lot (more than 2) of different memory areas with different access models and the situation that the stack is not usable for local var allocation. Here we have (again: "normally") no difference between global and local vars. Looking at the PSoC1 core which comes with just two registers there IS a difference between the performance of bank0-, bankN vars and locals. PSoC5 has got a modern core where there are no differences between memory accesses on the stack or in SRam.

             

           

             

          Bob 

          • 2. Re: Global vs Static Variables
            user_14586677

            Compiler and architecture matters, as we all agree.

               

             

               

            So we can have a compiler that does, or does not, make static vs global 

               

            vs local behave quite differently in terms of performance, RAM, stack, etc..

               

             

               

            The only real test is to test the code base on the machine of interest.

               

             

               

            Just look at the code reduction (FLASH) and RAM usage that occurs with Hitech.

               

            I can vouch for the fact it is significant, compared to Imagecraft. Needless to

               

            say it is accompanied by performance improvement as well.

               

             

               

            My conclusion to date is that there is a time and place for Globals, with attendant

               

            risks, and the same can be said for Locals and Static. There is not one answer

               

            to this discussion.

               

             

               

            Regards, Dana.

            • 3. Re: Global vs Static Variables
              user_1377889

              Yes, Dana, I agree with you. I prefer local vars because the stack memory management saves precious Ram.

                 

              Too bad that the HiTech C-compiler is obsolete, ImageCraft is really generating unnecessary page-register settings which are not optimized-out.

                 

               

                 

              Bob