Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

toward faster ArrayLists

3 views
Skip to first unread message

Roedy Green

unread,
Feb 19, 2012, 6:39:48 AM2/19/12
to
It has always bothered me that you have to pay such a high speed
penalty for ArrayLists when most of the time do nothing but access an
array for you.

What If ArrayLists were looked on more as primitives and implemented
as RAW arrays. When you got an ArrayIndexOutOfBoundsException, code
would jump into grow the array, but most of the time It would just
stay out the way.
--
Roedy Green Canadian Mind Products
http://mindprod.com
One of the most useful comments you can put in a program is
"If you change this, remember to change ?XXX? too".

Casey Hawthorne

unread,
Apr 15, 2012, 1:09:59 AM4/15/12
to
On Sun, 19 Feb 2012 03:39:48 -0800, Roedy Green
<see_w...@mindprod.com.invalid> wrote:

>It has always bothered me that you have to pay such a high speed
>penalty for ArrayLists when most of the time do nothing but access an
>array for you.
>
>What If ArrayLists were looked on more as primitives and implemented
>as RAW arrays. When you got an ArrayIndexOutOfBoundsException, code
>would jump into grow the array, but most of the time It would just
>stay out the way.

I haven't looked at the Java ArrayList code.

One could have a RAW array and if you got an
ArrayIndexOutOfBoundsException, another RAW array could be allocated
with more complicated indexing since you would need to know when you
are in the first or n'th RAW array.

When the ArrayList is idle (JVM has idel time?), then the RAW array
segments could be coalesced, giving a better amortized behaviour.

--
Regards,
Casey
0 new messages