Read only array, deep copy or retrieve copies one by one? (Performance and Memory)

Posted by Arthur Wulf White on Game Development See other posts from Game Development or by Arthur Wulf White
Published on 2012-10-19T09:51:04Z Indexed on 2012/10/21 23:20 UTC
Read the original article Hit count: 316

In a garbage collection based system, what is the most effective way to handle a read only array if such a structure does not exist natively in the language. Is it better to return a copy of an array or allow other classes to retrieve copies of the objects stored in the array one by one?

@JustinSkiles: It is not very broad. It is performance related and can actually be answered specifically for two general cases.

  1. You only need very few items: in this situation it's more effective to retrieve copies of the objects one by one.
  2. You wish to iterate over 30% or more objects. In this cases it is superior to retrieve all the array at once. This saves on functions calls. Function calls are very expansive when compared to reading directly from an array.

A good specific answer could include performance, reading from an array and reading indirectly through a function. It is a simple performance related question.

© Game Development or respective owner

Related posts about actionscript-3

Related posts about Performance