Global vs Static 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.
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Continuing discussion on variable usage. Attached.

   

 

   

Regards, Dana.

0 Likes
3 Replies
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
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

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.

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

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 

0 Likes