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 maikkel · Feb 23, 2012 at 11:33 PM · arrayjaggedmultidimensional

Jagged Arrays vs Multidimensional

I built my Minecraft-like block-world using 3d-Arrays of Objects (Block[x,y,z]).

Then i read everywhere that Jagged Arrays are much better performance wise. So I changed the whole code from 3d-Arrays zu Jagged Arrays with 3 Level depth (Block[x][y][z]).

It still works, but my benchmarking shows that EVERYTHING (from level build to block manipulation/Chunk rebuild) takes up to 2 times longer...

So now I'm reverting to the earlier version with 3D-Arrays.

Can somebody explain why Jagged Arrays actually seem to be slower than Multidimensional ones? Or is the problem that I changed all my foreach-loops to layered for-loops? That would be strange as well because for loops are supposed to be faster than foreach...

I'm confused...

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 Default117 · Feb 24, 2012 at 12:12 AM 0
Share

Either way, doing a $$anonymous$$ecraft clone instantiating geometry will be very inefficient.

avatar image maikkel · Feb 25, 2012 at 03:43 PM 0
Share

Why? I'm saving the vertice and uv positions in each block, then combine this information to the mesh for each chunk (normally 64x64x1 Blocks). And it Runs extremely fast, when I edit a block, it updates 3-6 Chunks and takes max. 0.004 seconds. What would you suggest to optimize (I know it sure isnt perfect but I dont see a better way than saving Block data in an Array of Objects, maybe just Arrays of Data)

1 Reply

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

Answer by Eric5h5 · Feb 24, 2012 at 12:40 AM

Accessing jagged arrays is over twice as fast as multi-dimensional arrays. When testing, you can only change one thing at a time, otherwise you don't know what changes caused the speed difference. However, the best performance is to use a 1D array rather than jagged or multi-d. So instead of

 block[x, y, z]

or

 block[x][y][z]

you would use

 block[x + (width*length*y) + (width*z)]

It's not much faster than a jagged array, but when dealing with zillions of blocks, it will make at least a little difference.

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 maikkel · Feb 25, 2012 at 01:38 PM 0
Share

Thank you. I think for the moment I'll just leave it as it is (with block[x,y,z]), since overall performance is quite good. Still, I find it very weird that everything ran much slower when I just changed the Arrays to Jagged...

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

pragma strict create List of Array of strings for class? 1 Answer

I don't know how to do multidimensional arrays 2 Answers

Can't access Array in a class instance multidimensional Array. 1 Answer

How do I save a three dimensional array? 1 Answer

print(var a = object) = null while print(oject) = what i want 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