- Home /
Should I remove items from a list if I dont need them ?
I am new to coding and just getting into it. I have couple of questions. Lets say I have a list that stores every item in the game and the owner of the item. If I was to have 100 unique items and 20 different owners it would be possible for the list to have as much as 2k items. 1. Is that much or pretty usual ? I will be doing a lot of loops through the list for search of specific item quite often. 2. Should I be removing items from the list I don’t need ? Does this affect the performance in any noticable way ? 3. I am making a medium-small scoped adventure game. Should I know of any future coding threats that I should prepare for now ?
So far I have script for file reading and decoding, and couple data structures. Coding is the truest Love & Hate relationship.
Answer by tiredamage42 · Jul 07, 2018 at 07:05 PM
If the objects you're taking out will be added back anyways then just I'd just leave them in.
Ive seen people use two copies of the data. One in a dictionary for search purposes (quicker than searching through an array or list) and ine in an array (use a list instead if the amount of objects is constantly changing) for iteration purposes.
You could also look into object pooling too
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
A node in a childnode? 1 Answer
C# GameObject Lists 2 Answers
How to get the name of a List from one of its items 1 Answer
List/buttons 1 Answer