Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail From: Jan Burse Newsgroups: comp.lang.java.programmer Subject: Re: setSize ArrayList, when will it come? Date: Wed, 10 Aug 2011 09:18:21 +0200 Organization: albasani.net Lines: 48 Message-ID: References: <1eadnROad6gX8NzTnZ2dnUVZ_tydnZ2d@earthlink.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net 42r7KcglMx6TCJTmOcaStq/9bAHUbQ56Y2HrStlMdrNYve9BLfqfNbImTn/h82Tvcgd+VJzVbulwvSUZrqwFBQ== NNTP-Posting-Date: Wed, 10 Aug 2011 07:18:22 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="h5BbrWKi7RdW3/TkTS6yL0ri411fKPsfAZPlQXA00PbZ0pj8/VFpAHm0JDhFFfvdQ0PYFjb+HOwvE6Odlp037SohuM6vaeFjy3gwYjc2xMvLzYDNOVQmG9J9Pgr+wMZo"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:5.0) Gecko/20110706 Firefox/5.0 SeaMonkey/2.2 In-Reply-To: Cancel-Lock: sha1:wHv1BWch2iIRojZ1rNyna3/2xG8= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6954 Knute Johnson schrieb: > That's BS. Either it's sparse enough to use a Map or it's too large to > use ArrayList and that would make it too large to use Vector. Just use > arrays, they're a lot faster than a Vector or any List. Or just get a > faster computer. > > I should have long since killed this thread. I am refering to the number of created temporary objects during the operation. See my other post. Using the official existing API with nCopies and addAll will use at least two additional temporary objects. But there is one more disadvantage of the helper going the official way approach. If you look at the addAll you see that it will repeatedly call add(). So it will repeatedly enlarge the ArrayList. So instead of jumping instantly to the desired size as a setSize implementation can do. It will temporarly create elementData arrays of different sizes until it has reached the final size. Given the 150% + 1 expension rule, if I do a setSize(100) from start it will create the following temporary elementData array objects: Nr Size 1 1 2 2 3 4 4 7 5 11 6 17 7 26 8 40 9 61 10 92 11 139 So there are 10 temporary array allocations, until we reach the final array. Also the resultinhg elementData has 39 excess place holders which I don't need. A setSize() implementation might just create the array right sized. So now you can go about and kill whatever you like. Bye