Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 ThisGuyThatsHere · Apr 04, 2017 at 04:33 PM · performancearraysram

How to store and iterate through a lot of Vector2s?

Hey,

I'm working on a random generator with pre-generating, so I don't really care about performance. However RAM usage goes really high with about 10k-20k of V2s, so what's the best way to store that amount of data for usage until everything is generated? I guess an array costs less RAM than a generic list (though is it a lot less?), but then are there any tricks like if you "translate" V2 to string, would it be visibly RAM cheaper with parsing?

And on side, what's the fastest way to iterate through that?

Edit: Thanks for additional information on the topic, I didn't really get into this stuff and when I hit a lot of RAM I was like, there is no infinite loop, no "100 times adding the same value to list" problem, so I thought that It may be that I'm using something not suitable for this etc. In the end I don't know what was wrong, just wrote the algorithm cleaner and it works for as many chunks as wanted.

Comment
Add comment · Show 2
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 MaartenB · Apr 04, 2017 at 08:04 PM 0
Share

Did you try translating your Vector2 to a string and performance test it next to a Vector2 array? That will answer all your questions. Just take 100 Vector2's and iterate through them in 2 different ways.

avatar image AndreM1 · Apr 04, 2017 at 08:27 PM 0
Share

It would help if you post what you're currently doing to reach that amount!

2 Replies

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

Answer by Bunny83 · Apr 04, 2017 at 09:38 PM

I don't see what you mean by high RAM usage. Even when you have 100k * Vector2 it's just 800KB of memory. That's not even 1MB.

The overhead between a generic List and a native Array is neglectable small. It's a constant total overhead of about 16 bytes. A List, if not initialized with a known capacity might have some spare capacity to increase performance of future additions. However that's nothing you should care about.

A single Vector2 is composed of two float values. A single float value has a size of 4 byte. So a Vector2 has a size of 8 bytes. A string representation of a Vector2 would require (in almost all cases) the same or even more memory as our decimal system is very inefficient (10 different values per byte while binary can store 256 values per byte)..

Also there are several different goals when optimising a process / system. Either memory efficiency or speed efficiency. Those two are in most cases mutually exclusive. It's often possible to reduce memory overhead by increased performance load or to increase performance by additional memory overhead. The question is what kind of optimisation is required.

If you don't have a concrete problem yet any optimisations would be premature optimisations.

Comment
Add comment · Show 1 · 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 Joe-Censored · Apr 04, 2017 at 10:42 PM 0
Share

Bunny83 is correct. 20,000 Vector2's should be a rather insignificant memory footprint for any modern computer or even phone. 20,000 Vector2's should take up only 156.25 kbytes of memory. You must have something else eating up your RA$$anonymous$$ that you haven't considered.

avatar image
0

Answer by AndreM1 · Apr 04, 2017 at 10:53 PM

I did manage to make some benchmarking, up to 2kk of vector2 on array, to keep them alive i set them as static an constantly changing some values, the garbage collector didn't seem to be much happy with it, but the size? 0.04 GB of ram, with 2.000.000 of vector2, you should really be more afraid of iterating over them wich proven to be kind of more slow. I also tested lists, wich proven to be the same thing

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

85 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity Tile Array vs Int Array Performance 0 Answers

GC Allocation with new array length 0 Answers

Performance question - Loading large-ish amounts of text data in a mobile game? 1 Answer

Is it faster to access an Vector3 array than to access a mesh's vertices? 2 Answers

List/Array should handle another List/Array - Upgrade System - Performance 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