|
Your explanation is very simple and correctly explains both methods. Here are some more comments ... till toenges wrote: It's almost correct, I would like the new code to be more tested before it fully replaces the old - in large arrays there's a big memory advantage, so it makes sense to replace, in small array it's almost the same, so the old code can stay for a while ...Kris Jurka wrote: Not all memory accesses are created equal :-), the Buffer1 is the biggest buffer, and the new code pass one more time through it. The last copy from Buffer3 to Buffer2 in the old method is done through System.arraycopy, which I think is very, very fast (hardware based), so the methods are more balanced ...more. The new method is always faster or at least as fast as the old method, because it requires fewer memory accesses. 3 Buffers: Buffer1 zeroing (vm intern) Buffer1 filling Buffer2 zeroing (vm intern) Buffer1 reading Buffer2 writing Buffer3 zeroing (vm intern) Buffer2 reading Buffer3 writing Total: 8 memory accesses. Eventually Buffer3 reading, but that's not part of the driver. 2 Buffers: Buffer1 zeroing (vm intern) Buffer1 filling Buffer1 reading (the new pass) Buffer2 zeroing (vm intern) Buffer1 reading Buffer2 writing Total: 6 memory accesses. Conclusion: The new method uses less memory. It must be faster as well, since everything else is fast in comparison to memory access. Additionally, it requires only 2 allocations, and memory allocation have some overhead as well, and mean more work for the garbage collector in the end. Even if the VM can do some magic to avoid zeroing the buffers, the newer method has one less memory access. It is always the winner. For large arrays the new is ALWAYS much faster off course - due to memory access.
--
Luis Flores Analista de Sistemas Evolute - Consultoria
Informática Tel: (+351) 212949689 AVISO DE CONFIDENCIALIDADE Esta mensagem de correio electrónico e eventuais ficheiros anexos são confidenciais e destinados apenas à(s) pessoa(s) ou entidade(s) acima referida(s), podendo conter informação privilegiada e confidencial, a qual não poderá ser divulgada, copiada, gravada ou distribuída nos termos da lei vigente. Caso não seja o destinatário da mensagem, ou se ela lhe foi enviada por engano, agradecemos que não faça uso ou divulgação da mesma. A distribuição ou utilização da informação nela contida é interdita. Se recebeu esta mensagem por engano, por favor notifique o remetente e apague este e-mail do seu sistema. Obrigado. CONFIDENTIALITY NOTICE This e-mail transmission and eventual attached files are intended only for the use of the individual(s) or entity(ies) named above and may contain information that is both privileged and confidential and is exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or use of any of the information contained in this transmission is strictly restricted. If by any means you have received this transmission in error, please immediately notify the sender and delete this e-mail from your system. Thank you. |