We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
vector or array? (Read 627 times)
vector or array?
Sep 1st, 2009, 4:53pm
 
one question, which is faster in terms of cpu consumption? to use vector or arrays?

thanks
Re: vector or array?
Reply #1 - Sep 1st, 2009, 9:08pm
 
arrays.  But, that's slower if you have to change their size.  (at least during the moment that you're doing the size change.)  Pretty negligible either way.  --Ben
Re: vector or array?
Reply #2 - Sep 2nd, 2009, 7:09am
 
It depends...
On your usage, as BenHem pointed out.
If you know in advance the size of the data, arrays are always better in terms of size and speed.
If you need to grow the storage area, ArrayList is probably better (Vector is old and slow...), as something like append() creates a new array of same size plus one, copies the old data there and put the appended data at the last position. Quite costly... OK on relatively small arrays, as BenHem says, but for some millions of entries, it can become a bottleneck.
Page Index Toggle Pages: 1