3 Replies Latest reply on Jan 4, 2013 7:38 AM by user_1377889

    Global vs Local Variables

    user_1377889

      Having recently discussed the use of global and local variables with Dana, I could not help but writing a bit of explanation for those who are not so experienced in the matter. Have a look at the attached document.

         

       

         

      Happy new year for all you forum supporters

         

      Bob

        • 1. Re: Global vs Local Variables
          junichi.hiraoka
                  Global variables are convenient but, Software engineering said, Should be decrease using of Global variables. I'm used to do this strategy. In case of PSoC1 Some additional considerations are needed, I think. 1) In interruption handler Have to use PAGE0 RAM area (it's better). And use VOLATILE statement with global variable. 2) If need to keeping value Use a static variable as possible, It behaves like a local variable. +++ Happy New Year for all Pal +++   
          • 2. Re: Global vs Local Variables
            user_14586677

            Global vs Static Variables, attached.

               

             

               

            Regards, Dana.

            • 3. Re: Global vs Local 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