Reusing an Array

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Reusing an Array

Thelliez
Assuming a large number of iterations (max 10,000) through a method
creating a temporary Array; is it ok to create an Array instance over
and over? Or should the instance be 'emptied' and reused at each call?

Thanks,
Thierry
Reply | Threaded
Open this post in threaded view
|

Re: Reusing an Array

Jon Paynter-2

On Mon, Oct 18, 2010 at 12:13 PM, Thierry Thelliez <[hidden email]> wrote:
Assuming a large number of iterations (max 10,000) through a method
creating a temporary Array; is it ok to create an Array instance over
and over? Or should the instance be 'emptied' and reused at each call?
Well - if your code depends on the size of the array, and the size varies, then it may work to re-create it all the time.  but if he size wont change, then creating the array first, and re-using it will save you the overhead of re-creating the array everytime.

But the overal best way is to try both implementations, and use the profiler to see which one works best:  ProfMonitor monitorBlock: [  ]

Reply | Threaded
Open this post in threaded view
|

Re: Reusing an Array

Dale Henrichs
In reply to this post by Thelliez
On 10/18/2010 12:13 PM, Thierry Thelliez wrote:
> Assuming a large number of iterations (max 10,000) through a method
> creating a temporary Array; is it ok to create an Array instance over
> and over? Or should the instance be 'emptied' and reused at each call?
>
> Thanks,
> Thierry

Thierry,

I think that the GemStone in-image garbage collector is pretty efficient
relative to the creation of small, short-lived objects (never making it
out of eden or new space)... If the temp array is getting large
(probably 1000's of slots) then it might make sense to reuse the array ...

Dale