You are here

Global vs Local Variables | Cypress Semiconductor

Global vs Local Variables

Summary: 3 Replies, Latest post by Bob Marlowe on 04 Jan 2013 07:38 AM PST
Verified Answers: 0
Last post
Log in to post new comments.
user_1377889's picture
9284 posts

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


user_119377051's picture
866 posts

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 +++

user_14586677's picture
7646 posts

Global vs Static Variables, attached.


Regards, Dana.

user_1377889's picture
9284 posts

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.




Log in to post new comments.