Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® Software > Global vs Static Variables

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



Global vs Static Variables
Moderator:
JFMD

Post Reply
Follow this topic



Global vs Static Variables

danaaknight posted on 04 Jan 2013 4:07 AM PST
Top Contributor
1773 Forum Posts

Continuing discussion on variable usage. Attached.

 

Regards, Dana.




Re: Global vs Static Variables

Bob Marlowe posted on 04 Jan 2013 05:36 AM PST
Top Contributor
1768 Forum 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.

 

Bob 



Re: Global vs Static Variables

danaaknight posted on 04 Jan 2013 06:19 AM PST
Top Contributor
1773 Forum Posts

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.



Re: Global vs Static Variables

Bob Marlowe posted on 04 Jan 2013 09:32 AM PST
Top Contributor
1768 Forum Posts

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 






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: GRAA; Secondary Owner: RAIK; Sunset Date: 01/01/20