Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AtomicIntegerArray vs AtomicInteger[]

Is there any difference in meaning of AtomicIntegerArray and AtomicInteger[]? And which one is faster to use? (only thing that I noticed is that first is taking much less space, but that means that each recheck is checking boundaries of array, so that would make it slower?)

Edit: In a scenario where array is pre-initialized.

like image 474
Sarmun Avatar asked Mar 28 '09 12:03

Sarmun


1 Answers

AtomicInteger[] will require an object per element. AtomicIntegerArray just requires the AtomicIntegerArray object and an array object. So use the latter if possible.

The cost of bounds checking is quite small even for normal arrays. What might be significant is that access to data in the same cache line from multiple processors can cause significant performance issues. Therefore separate objects, or deliberately avoiding close elements of an array, can help.

like image 173
Tom Hawtin - tackline Avatar answered Oct 19 '22 23:10

Tom Hawtin - tackline