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

java.io.RandomAccessFile: Improve performance without affecting derived classes

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: 1.2.0
    • Fix Version/s: None
    • Component/s: core-libs
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description



      Name: clC74495 Date: 11/27/98


      Bug Reports 4137835 and 4170047 concerned performance
      enhancements to java.io.RandomAccessFile. A set of
      simple changes to RandomAccessFile preserves the
      derived class behaviour of the current version
      and yet gives the performance boost originally
      suggested. The concept of a temporary buffer
      was rejected as being too costly in object creations.
      This would be the case if a new buffer was used
      for each call.

      The solution is to use a SINGLE buffer for all
      read and write calls. A single 8-byte array is
      allocated on RandomAccessFile instantiation and
      retained throughout its life. This is NOT a
      very heavy price to pay for performance gains
      of up to 800% !!

      For example readShort() changes from

      public short readShort() {
      int ch1 = read();
      int ch2 = read();
      if (ch1 < 0 || ch2 < 0)
        throw new EOFException();
      return (short) ((ch1 << 8) + (ch2 << 0));
      }

      Add an object instance variable:
        private byte[] tmpBuf = new byte[8];

      public short readShort() {
      if (2 != read(tmpBuf, 0, 2))
        throw new EOFException();
      return (short)((tmpBuf[0] << 8) + (tmpBuf[1] << 0));
      }

      Similar changes can be made to all the multi-byte
      read and write methods.

      email me for a copy of the file with the changes
      already made (###@###.###)
      (Review ID: 43137)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mr Mark Reinhold
              Reporter:
              clucasius Carlos Lucasius (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: