Serializing strings

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thomas Dybdahl Ahle

    Serializing strings

    Hi, do anybody know, if it has ane performace loose, to send a string in a
    objectoutputste ram instead of sending it through a standard outputstream?

    --
    Programmers should realize their critical importance and responsibility in a
    world gone digital. They are in many ways similar to the priests and monks of
    Europe's Dark Ages; they are the only ones with the training and insight
    to read and interpret the "scripture" of this age.

  • Oliver Wong

    #2
    Re: Serializing strings

    "Thomas Dybdahl Ahle" <thomas@localho st.localdomain> wrote in message
    news:pan.2005.1 0.02.19.34.30.8 32163@localhost .localdomain...[color=blue]
    > Hi, do anybody know, if it has ane performace loose, to send a string in a
    > objectoutputste ram instead of sending it through a standard outputstream?[/color]

    "ObjectInputStr eam" IS a "OutputStre am" in the sense that the
    ObjectInputStre am class extends the OutputStream class, and
    ObjectInputStre am is part of the Java2 5.0 API, so I don't know how much
    more "standard" it can be.

    Performance questions are almost always compiler dependent though. If
    two methods have exactly the same output and side effects, there's no reason
    why a sufficiently smart compiler couldn't optimize the slower one to behave
    with the exact same speed as the faster one.

    - Oliver


    Comment

    • UniDyne
      New Member
      • Oct 2005
      • 18

      #3
      The performance loss is minimal in most implementations . It depends on the JVM and the compiler.

      Generally, the data written to the ObjectOutputStr eam will be the same as if calling writeUTF() on the underlying OutputStream. There is one key difference though and this is true of all Java objects written to ObjectOutputStr eams:

      If you use writeObject() multiple times for the same object instance, only the first call will write an actual copy of the object's data. All subsequent calls will only write a reference to the data written by the first.

      SO... if you are going to write the String only once, there is no difference between writeObject() and writeUTF(). Otherwise, you will get smaller files with writeObject() - with a slight performance hit because you are keeping track of the object's reference.

      Comment

      Working...