Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Joshua Cranmer Newsgroups: comp.lang.java.programmer Subject: Re: setSize ArrayList, when will it come? Date: Wed, 10 Aug 2011 18:16:57 -0500 Organization: A noiseless patient Spider Lines: 30 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 10 Aug 2011 23:17:04 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="B3q1fNdvNsCxx/IZ4idKGA"; logging-data="31363"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+H86NLUriNhj8g3/NNmGUx7iJ61aXXUpI=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0 In-Reply-To: Cancel-Lock: sha1:jXcESSlMIBsDvsgbPnmEoKtWBuI= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6996 On 8/10/2011 2:04 AM, Jan Burse wrote: > Joshua Cranmer schrieb: >> Or you could use addAll and Collections.nCopies to implement setSize, >> and use ListIterator to do reverse iteration. > > No you didn't get it. I need a fast specialized > setSize() as argued in the bug reference. According > to the collections documentation, the nCopies method > does create an extra object: > > http://download.oracle.com/javase/1.4.2/docs/api/java/util/Collections.html#nCopies%28int,%20java.lang.Object%29 > > ... The newly allocated data object is tiny (it contains > a single reference to the data object). ... > > But it is not only that this tiny object of type > Collections.CopiesList will be created. For addAll > call an Iterator AbstractList.Itr will be > created I guess, not sure. Okay, if you're so annoyed about the creation of several objects, you can create your own version of a CopiesList that implements both Collection and Iterator and implements everything on itself, for a single overhead of around 12 bytes. If that is still too much, run a garbage collection. You now have a few hundred extra kilobytes of data. If you're still complaining, you're using the wrong language. -- Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth