Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4112544

RFE for component tracking in Container.java

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.1.6
    • client-libs
    • sparc
    • solaris_2.6



      Name: diC59631 Date: 02/16/98


      The following code (share/java/java/awt/Container.java) seems to be doing a lot
      of arraycopy and reallocation of arrays by doubling the arraysize.
      I wonder why it cant be implemented as component list, where
      - no need to allocate such big array by doubling the arraysize
      - insertion of components becomes easier
      - no array copies.
      - Specially, in the case of embedded platforms, it would use more memory and
        may be would be less efficient.
      For ex. if I consider 50 components to be inserted in some random order, it would
      - reallocate arrays 5 times
      - Garbage collection a no. of times &
      - arraycopy more than 50 times.
      This delay just multiplies

                  /* Add component to list; allocate new array if necessary. */
                  if (ncomponents == component.length) {
                      Component newcomponents[] = new Component[ncomponents * 2];
                      System.arraycopy(component, 0, newcomponents, 0, ncomponents);
                      component = newcomponents;
                  }
                  if (index == -1 || index == ncomponents) {
                      component[ncomponents++] = comp;
                  } else {
                      System.arraycopy(component, index, component,
                                       index + 1, ncomponents - index);
                      component[index] = comp;
                      ncomponents++;
                  }
      (Review ID: 25082)
      ======================================================================

            serb Sergey Bylokhov
            dindrigo Daniel Indrigo (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: