Global vs Local Variables

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

0 Likes
3 Replies
Anonymous
Not applicable
        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 +++   
0 Likes
lock attach
Attachments are accessible only for community members.
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Global vs Static Variables, attached.

   

 

   

Regards, Dana.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

   


 

0 Likes