Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by schwertfisch · Dec 20, 2010 at 09:02 PM · iosstaticvarcpuheavy

Static variables heavy for the iphone's CPU?

I use static variables quite a lot. I have a basic movement script for my main character and have lots of static vars (ok at the moment they are 8, I actually don't know if this is "lots") in it. The behavior of the other objects depends a lot on these static variables.

I was wondering if this is heavy for the iphone's cpu, as the device will have to switch from reading the various object's scripts to reading the static variables value from my basic script.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by BerggreenDK · Dec 20, 2010 at 09:10 PM

If its 8 variables, I dont think you will be able to notice nor benchmark the difference. If you have a tilemap of 1024x1024 blocks in a global array perhaps. I dont know enough about how unity handles "statics".

Another thing is also to think of how often do you read/write to these variables? once a minute or everyframe?

Sometimes statics are both easier and faster than using functions to access the same variables.

My guess would be its faster this way at the moment, but without insight in your actual code, its hard to tell.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image schwertfisch · Dec 20, 2010 at 11:18 PM 0
Share

Thanks Berggreen, the static variables are read from and written to from inside "OnTriggerEnter" functions. So I understand it's better than if I had them inside "update" functions?

avatar image BerggreenDK · Dec 23, 2010 at 02:23 AM 0
Share

if you only have 8 I wouldnt really bother to think so much about them. There is something called a 80/20 rule. 80% of the actual gameloop(CPU) is run on 20% of the code. Just check where your variables are. Try to benchmark it if you think its slow. I would.

avatar image
0

Answer by ChrisMasterton · Mar 21, 2012 at 12:07 AM

The fact that your variables are static won't make any difference. None.

Accessing variables through a function incurs the penalty of a function call. So in the simplest case direct access to the variable will be faster.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by ChrisMasterton · Mar 21, 2012 at 12:07 AM

The fact that your variables are static won't make any difference. None.

Accessing variables through a function incurs the penalty of a function call. So in the simplest case direct access to the variable will be faster.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

How to use a static var 2 Answers

My unity ios build is taking more than 2 hours 0 Answers

Can Apps ask for CPU power? 1 Answer

Static variables explanation. 2 Answers

guitexture a static var? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges