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 Breaking_Reality · Apr 05, 2019 at 07:45 PM · listpooling

Using Stack vs A list in my pool script

Hello! I've made plenty pool systems for many games I've worked on. I started work on a new project and I created a pool system. However for some reason I decided to do some reading on pooling because I was interested in how other did their systems. I found that many used Stack over something like a list or an array list. I never used stack but what I want to know is... is stack better for performance in a pool system or something like a list or array would be better. Thanks!

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 Bunny83 · Apr 05, 2019 at 09:20 PM

Both the Stack and the List use a native array internally. It doesn't really matter if you use a List or a Stack, though it depends on how you use them. For example Adding to the end of the list or removing from the end is as cheap as Stack push / pop. However if you remove the first element in the list you get a lot of overhead since every remove operation has to move all remaining elements around

Comment
Add comment · Show 4 · 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 Breaking_Reality · Apr 05, 2019 at 09:24 PM 0
Share

Ah ok understood. Thanks for the answer!

avatar image Breaking_Reality · Apr 05, 2019 at 09:25 PM 0
Share

What if I removed the LAST object in the List? Would it still move all the items in the list?

avatar image RobAnthem · Apr 05, 2019 at 10:14 PM 0
Share

Curiously, would it be more efficient (in a list) to swap the element you are intending to remove with the last element in the last, and then removing the last element? If the usage of the order of elements doesn't matter that is.

avatar image Bunny83 RobAnthem · Apr 06, 2019 at 02:47 AM 0
Share

Yes, of course. This is actually a common solution if arbitrary elements need to be removed and the order doesn't matter. Though you actually don't need to swap them. Just copy the last element over the element you want to remove and then drop the last element. A List is essentially just a wrapper class for an ordinary array. It only has an additional integer field to remember the current element count. $$anonymous$$ethods like Add may create a new internal array if the current array capacity isn't large enough for the newly added value. Removing the last element essentially just sets the last element to null (default(T)) and decrements the count.

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

107 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 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

A node in a childnode? 1 Answer

how to create random list of two diffrent prefab 1 Answer

How to increase rate of a falling object in pooling object? 1 Answer

How to pull two objects at the same time? 0 Answers

Object Pooling for Class Pattern 0 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