D
Daniele Futtorovic
On 5/8/2013 9:45 PM, Eric Sosman wrote:
On 5/8/2013 9:04 PM, Arne Vajhøj wrote:
On 5/8/2013 9:57 AM, lipska the kat wrote:
[...] the following two lines are
logically equivalent.
1. Byte[][] bytes = new Byte[width][height];
2. byte[][] bytes = new byte[width][length]
Not at all.
You will eventually end up with 1+width*height and 1 objects
respectively.
No; both will generate 1+width objects:
- One array containing `width' references to other arrays,
- `width' arrays containing `height' bytes or Byte
references.
A *really* stupid coder might use Byte[][] *and* populate
the arrays with `new Byte(value)' repeated `width*height' times;
that would produce `1 + width + width*height' objects in all.
Autoboxers would be unlikely to enter that particular trap --
but even so, a four- to eight-fold memory bloat is not to be
sneezed at.
Ooops.
1+width+width*height and 1+width objects.
I would still expect the byte version to end up
with width*height Byte objects.
If there are no null and no reused objects, then
I can not see how that can be avoided.
Are you saying that Java will intern so aggressively
that there will be reused objects?
Autoboxing will you Byte#valueOf, which returns pooled instances.
*will _use_