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 Setzer22 · Jan 20, 2013 at 03:33 PM · memorycost

Am I wasting memory with this? Alternatives?

Hello everyone,

I was just wondering if what I'll try to explain is an innecesary waste of memory or is actually fine.

Let's say I have a class (we'll call it Information), which holds quite a lot of data (not that much, a couple of float values, a texture2D, strings...), and I want to add a pair of values int/Information, to a queue. Of course I can't do that, as the generic queue only accepts for one type to be added, so I was thinking on creating a new class Information_with_int, which containt an instance of the class Informtion, and an integer, then passing that new data type to the method.

So I was wondering, am I increasing the memory cost (i mean greatly) by doing this? When I create an instance for the new class will I waste the whole memory an Information instance takes? (plus the memory an integer takes which is quite neglectable at this point). Or as it's all done by references, it will only waste the little bit of memory is needed to hold those pointers?

I don't know many things which happen at low level so the only thing left is asking (and of course, search the web, but something like this isn't generating many valid search results, it will take a lot of time studying to figure out some basic doubt).

Thank you very much!

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
1
Best Answer

Answer by whydoidoit · Jan 20, 2013 at 03:36 PM

Your new class would just take the memory for a reference to the instance (4 bytes) plus an int (4 bytes). You might consider using a struct as it won't then need garbage collecting when you are done with the instance in the queue.

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 Setzer22 · Jan 20, 2013 at 03:44 PM 0
Share

Thank you! that's what I was looking for.

And You're right, using an struct might be better, but as they are value types (not reference), I'll get a copy when passing to a method. Then, what would the copy actually be, a copy for the two refferences, o a copy for the whole class plus the integer?

I'd bet it's the first one, but I better be sure about it before jumping into the code.

avatar image whydoidoit · Jan 20, 2013 at 03:46 PM 0
Share

Yes, just a copy of the reference and a copy of the int.

avatar image Setzer22 · Jan 20, 2013 at 03:54 PM 0
Share

Thanks again, quick and simple! I've marked this as answered and voted up.

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

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Efficient access to Mesh arrays 1 Answer

Modo memory use increases steadily 0 Answers

Device specific texture resolutions? 1 Answer

Assetbundle loaded asset cannot be cleaned in Android 1 Answer

Why a texture always consume twice RAM when running? 1 Answer


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