Re: compare two byte[] 's



Mark Space wrote:
What does bother me is the lack of utility built into arrays. Changing #equals() or #clone() now would likely be too difficult, but I don't see the harm in adding new methods. All of the very similar overloaded methods in java.util.Arrays, for example, would fit neatly into instance methods of an array class. I honestly can't figure out why this hasn't been done.

This is one possible reason:

Since each array is its own special class, the virtual machine has to synthesize special class objects for arrays. The developers made a choice to keep these objects as small as possible. One thing that could really bloat these objects would be to have to define methods for /every/ single array type.

java.util.Array's toString method has 75 bytes for Object[] and 72 for <primitive>[]. The hashCode methods are between 45 and 56 bytes. The equals methods are between 54 bytes and 78 bytes.

Even ignoring whether or not you want equals to be == or .equals equality, that's 206 bytes for just the bytecode operations for an Object[] class. I'm not including the overhead for method definitions.

I'm willing to bet that the code for Object.clone() special-cases array cloning, just to avoid having to redefine all of these methods.

I'd also imagine that this setup makes the code generation easier: there's only a few bytes that have to be modified, even across primitive and reference type arrays.

--
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth
.



Relevant Pages

  • Re: Using INDEX twice??
    ... ...and then use conditional formatting to hide any error value that may ... to the first cell in the range) which meets the specified criteria. ... IF function returns an array of numbers, ... FALSE*TRUE equals 0 ...
    (microsoft.public.excel.worksheet.functions)
  • Re: This should be easy...
    ... > saying if the range B2:D2 is blank, then column equals zero? ... and the results will be returned as an array which MAX works on. ... > "Total" cell. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Discarding unread data after scanf()
    ... A call to fscanf with stdin as the first argument, ... ** If rc equals EOF, then the end of file was reached, ... then there is a string in the array. ... ** then the extra characters are discarded. ...
    (comp.lang.c)
  • Simple Perl
    ... print header, start_html("Carrier Validation Test Architecture"), ... while values of the array are not empty. ... if the array value equals blank. ...
    (comp.lang.perl.misc)
  • Re: compare two byte[] s
    ... All of the very similar overloaded methods in java.util.Arrays, for example, would fit neatly into instance methods of an array class. ... Since each array is its own special class, the virtual machine has to synthesize special class objects for arrays. ... Hobbit while listening to Radiohead's Hail to the Thief. ...
    (comp.lang.java.programmer)

Loading