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: Bulk Array Element Allocation, is it faster? Date: Sun, 25 Sep 2011 10:47:02 +0200 Organization: albasani.net Lines: 34 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net ZP5kxbc07/stwOykOslLqmYlm4cMI/HOwxS8KQzyPXeDnzCeI2PgZ1P/Sh1blR28sbVGmLiW4cT4u76ycWpHispeUK6WjyplqGPUeJz9X7fb7IebqYfdRtNHBX+dRVR2 NNTP-Posting-Date: Sun, 25 Sep 2011 08:47:02 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="hjzYNkkQYh/aT1QSGzLHBPutVKxKuZgPXJuRxhvVTKk5wlfTqwJfIgWwYWr04qW6J2d29auKBNzbiTNzUuBUdU/+Pet5dAHKO26jSQAcqLKJ9UVVLLAaemQIDvabSFyj"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:6.0.2) Gecko/20110902 Firefox/6.0.2 SeaMonkey/2.3.3 In-Reply-To: Cancel-Lock: sha1:Ow+i4Nde2xat8L1sleZkONO5aYU= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:8284 Roedy Green schrieb: > new does two things: > 1. allocates X bytes of space > 2. initialises that block of space to a pattern. So a dumb translation of the loop would be: 1. for each i between 0 and n-1 1.1 allocates X bytes of space 1.2 call the initializer Then I was more thinking that the loop does the following, i.e. is cleverly compiled to: 1. allocates n*X bytes of space 2. for each i between 0 and n-1 2.1 call the initializer for location X*i At least I would hand assembler it like this. Saving n-1 calls to the heap allocator. But maybe positive effect is not based on such a clever allocation and only on what Patricia said. I was already googling a little bit about the compilation techniques found for JIT today, but did not yet hit any evidence for clever loop allocation, but it is so obvious I really it must be done. But maybe it is not done because of multi-threading or GC, who knows... Bye