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 jjobby · Mar 26, 2011 at 03:54 PM · performance

Question about "new" keyword and performance

I've read that we should avoid allocating memory at runtime. Does this apply to every type of variable? I know that I shouldn't use new to initialize reference class object at runtime. But what's about struct like Vector2 or Vector3? Should I avoid to create (using new) them at runtime too?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by loopyllama · Mar 26, 2011 at 09:34 PM

anytime you want to set any component of a transform you have to call new Vector3, directly in c sharp and under the hood in javascript. to quote trinity from the matrix, "Dodge this!"

Comment
Add comment · Show 3 · 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 jjobby · Mar 27, 2011 at 10:48 AM 0
Share

What I don't understand is that Vector3 is a value type. Its properties are float. What's so much different between create new Vector3 and create three new float variables?

avatar image loopyllama · Mar 27, 2011 at 11:52 AM 0
Share

there isn't too much difference. under the hood, floats are structs in .net. my point is that you can't avoid new Vector3 at runtime, so why worry? what kinds of trouble are you running into that causes you to ask your question? There are many knowledgeable people in the community that can quickly answer a very specific question.

avatar image jjobby · Mar 27, 2011 at 08:32 PM 0
Share

So, you basically mean that I shouldn't worry about it right? I also use new Vector3 but the use of new keyword makes me curious if it's appropriate or not. Because I've read that it's a bad thing to frequency create new object at runtime. Thanks for the answer. :)

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

No one has followed this question yet.

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Total memory allocated increases indefinately from .80GB untill crash 3 Answers

Efficient AutoFire Burst Script Help 2 Answers

What are the benefits of using Invoke over Coroutine or vice versa? 1 Answer

FixedUpdate performance doubts 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