Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Java ArrayList 1.7

Name: Anonymous 2011-11-30 10:39

http://www.docjar.com/html/api/java/util/ArrayList.java.html


  374       /**
  375        * Returns the element at the specified position in this list.
  376        *
  377        * @param  index index of the element to return
  378        * @return the element at the specified position in this list
  379        * @throws IndexOutOfBoundsException {@inheritDoc}
  380        */
  381       public E get(int index) {
  382           rangeCheck(index);
  383  
  384           return elementData(index);
  385       }

 596       /**
  597        * Checks if the given index is in range.  If not, throws an appropriate
  598        * runtime exception.  This method does *not* check if the index is
  599        * negative: It is always used immediately prior to an array access,
  600        * which throws an ArrayIndexOutOfBoundsException if index is negative.
  601        */
  602       private void rangeCheck(int index) {
  603           if (index >= size)
  604               throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
  605       }



What's the point of having a range check if it only checks if the index is >= to the size and not if it's < 0. This seems stupid and a waste of a method call.



  171       /**
  172        * Increases the capacity of this <tt>ArrayList</tt> instance, if
  173        * necessary, to ensure that it can hold at least the number of elements
  174        * specified by the minimum capacity argument.
  175        *
  176        * @param   minCapacity   the desired minimum capacity
  177        */
  178       public void ensureCapacity(int minCapacity) {
  179           if (minCapacity > 0)
  180               ensureCapacityInternal(minCapacity);
  181       }
  182  
  183       private void ensureCapacityInternal(int minCapacity) {
  184           modCount++;
  185           // overflow-conscious code
  186           if (minCapacity - elementData.length > 0)
  187               grow(minCapacity);
  188       }


ensureCapacity is never called, yet they have it in the class.


BLOAT

Name: Anonymous 2011-12-01 21:33

You would think that memory consumption would be a large factor for a large-scale database. That's what I don't get with all the projects like Cassandra, Hadoop, etc: Why do they use Java, where they have to deal with the memory overhead of object allocations, jagged arrays, forced signedness, etc.
I can see how the overhead of the JVM itself and the JIT isn't so significant in large server configurations, but you never have enough RAM in big data, so how can they afford to waste X% of it?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List