![]() ![]() Note also that Lists really just do on fixed-length arrays anyway when necessary-they start out with a capacity of 4 (unless otherwise specified), and keep doubling that any time the capacity is exceeded. The simpler the type, the greater the speed difference. However, a GameObject array is barely any different than List. An int array, for example, was about 6X faster than List. Note that the speed difference depends on the type used in the array. ![]() The exception to this is if you're an experienced programmer and know for sure that a certain optimization is necessary to perform a certain task, then you probably are better off implementing the optimization ahead of time. My bottom line is that you should try to use what's easy and readily available and start focusing on optimization once you notice that there is a pressing need for it (by using a profiler for example). The question is how productive you'll be with everything super optimized and how much bang you get for the buck. That is how optimization should be done, not deciding too much about lower detail stuff, but of course it adds to it. Instead of testing 10000 objects, you might end up testing only 10 objects. A better approach for this would be to divide and conquer the problem by grouping objects in a hierarchical manner and effectively cull (ignore) the objects that aren't anywhere near. ![]() For instance, if you wanted to check which object out of 10000 objects are closest to you, you'd naively check each object and keep track of the one that has the least distance to you. But the best optimization you can make is figuring out how you can make the least amount of work that you need to. By organizing your objects in different ways you can benefit from your computers cache, avoiding cache misses and RAM lookups which can boost performance a lot. Your memory usage patterns could benefit from special memory curves for instance if you frequently access objects left, right up and down an element in a 2d array. It is not the raw access speed you should be concerned about, but what you are doing per object. ![]() Whatever you are doing per object in an array is probably going to take significantly longer time to process making the difference negligible. Arrays are faster, but read/write is such a small overhead these days. Arrays are faster in raw access speed, but lists will manage memory faster and more efficiently than resizing arrays frequently, as in your example. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |