You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-user@hadoop.apache.org by Jim Donofrio <do...@gmail.com> on 2012/04/25 05:01:21 UTC

why does Text.setCapacity not double the array size as in most dynamic array implementations?

   private void setCapacity(int len, boolean keepData) {
     if (bytes == null || bytes.length < len) {
       byte[] newBytes = new byte[len];
       if (bytes != null && keepData) {
         System.arraycopy(bytes, 0, newBytes, 0, length);
       }
       bytes = newBytes;
     }
   }

Why does Text.setCapacity only expand the array to the length of the new 
data? Why not instead set the length to double the new requested length 
or 3/2 times the existing length as in ArrayList so that the array size 
will grow exponentially as in most dynamic array implentations?


Re: why does Text.setCapacity not double the array size as in most dynamic array implementations?

Posted by Jim Donofrio <do...@gmail.com>.
Sorry, I just stumbled across HADOOP-6109 which made this change in 
trunk, I was looking at the Text in 1.0.2. Cant get this fix get 
backported to the Hadoop 1 versions?

On 04/24/2012 11:01 PM, Jim Donofrio wrote:
> private void setCapacity(int len, boolean keepData) {
> if (bytes == null || bytes.length < len) {
> byte[] newBytes = new byte[len];
> if (bytes != null && keepData) {
> System.arraycopy(bytes, 0, newBytes, 0, length);
> }
> bytes = newBytes;
> }
> }
>
> Why does Text.setCapacity only expand the array to the length of the new
> data? Why not instead set the length to double the new requested length
> or 3/2 times the existing length as in ArrayList so that the array size
> will grow exponentially as in most dynamic array implentations?
>