Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx05.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: How to convert image into Hex 2 Dimensional Array? Date: Wed, 08 May 2013 12:52:54 -0400 Organization: A noiseless patient Spider Lines: 52 Message-ID: References: <41718873-b1a6-4b97-bbbb-8002c48d4e29@googlegroups.com> <_4uit.18441$MS1.11557@newsfe05.iad> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 8 May 2013 16:49:24 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="0d73d8cc209bff1c6395088b400d0605"; logging-data="9803"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+p5BrzqzZU4LX9AR350FR8" User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130328 Thunderbird/17.0.5 In-Reply-To: <_4uit.18441$MS1.11557@newsfe05.iad> Cancel-Lock: sha1:zbaX5xlpmiAT4ZQ1iQc4OFZkY5k= Xref: csiph.com comp.lang.java.programmer:23938 On 5/8/2013 11:22 AM, Daniel Pitts wrote: > On 5/8/13 6:57 AM, lipska the kat wrote: >> On 08/05/13 14:19, Daniele Futtorovic wrote: >>> On 08/05/2013 10:06, lipska the kat allegedly wrote: >>>> Byte[][] bytes = new Byte[width][height]; >>> >>> Lipska, mind the difference between Byte and byte. That code above is >>> extremely bad advice. >> >> Why? it's common practice these days to eschew primitives and use >> (autoboxing) classes > Common practice where? Cite a credible source or I'll be forced to think > that you are just making up facts to support your mistake. My 4 year > old daughter does that; you want to be more credible than my 4 year old, > don't you? > >> it's more consistent in OO code and, as I >> understand things, post autoboxing, the following two lines are >> logically equivalent. >> >> 1. Byte[][] bytes = new Byte[width][height]; >> 2. byte[][] bytes = new byte[width][length] > > Even ignoring the typos, those are nothing alike. > > Auto-boxing is a convenience, but does not make those two things the > same, even by a long shot. For example, consider what happens when `int x = bytes[0][0];' immediately follows either of the above. In case 2, it sets x to zero. In case 1, the JVM throws NullPointerException. That's not "logically equivalent" in my book! >[...] > Personally my decision on whether to use Byte vs byte would hinge solely > on the question "do I want to store nulls in this?" Or on "Do I want to put it in a Collection?" There's also the matter of the memory footprint, even if "efficiency" is a dirty word in some circles. Version 1 will use four times (32-bit JVM) or eight times (64-bit) as much memory as version 2. Image sizes vary, but even a fairly modest 640x480 has 300K pixels -- so using Byte[][] instead of byte[][] would cost an extra 0.9MB or 2.1MB. Even if I had the desire to store nulls, a bloat of such proportions would probably prompt me to use byte[][] and seek another way to represent whatever I wanted the nulls to stand for. -- Eric Sosman esosman@comcast-dot-net.invalid