serialising Arraylists

Discussion in 'Java' started by Roedy Green, Sep 8, 2003.

  1. Roedy Green

    Roedy Green Guest

    I wondered if anyone has experimented with serialising ArrayLists.
    Are they substantially more compact if you convert them to arrays
    first?

    Are there dummy elements past the last used? Is there substantially
    more type information embedded?

    I will likely to some experiments myself to find out. I just thought
    I would start the conversation about it.




    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Sep 8, 2003
    #1
    1. Advertising

  2. Roedy Green

    Roedy Green Guest

    On Mon, 08 Sep 2003 00:03:52 GMT, Roedy Green <>
    wrote or quoted :

    >I wondered if anyone has experimented with serialising ArrayLists.
    >Are they substantially more compact if you convert them to arrays
    >first?
    >
    >Are there dummy elements past the last used? Is there substantially
    >more type information embedded?
    >
    >I will likely to some experiments myself to find out. I just thought
    >I would start the conversation about it.


    The good news is there is almost no difference. An ArrayList 1000 long
    containing 100 objects is only 4 bytes longer than an array containing
    100 specific objects.

    I wondered if serialized interned strings are guaranteed to
    reconstitute as interned. It is one thing to do an experiment and
    discover they are, but quite another know the behaviour is prescribed.

    Ditto, do unique strings coming back necessarily have map onto
    different copies.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Sep 8, 2003
    #2
    1. Advertising

  3. Roedy Green

    Tim Tyler Guest

    Roedy Green <> wrote:

    : I wondered if serialized interned strings are guaranteed to
    : reconstitute as interned. It is one thing to do an experiment and
    : discover they are, but quite another know the behaviour is prescribed.

    : Ditto, do unique strings coming back necessarily have map onto
    : different copies.

    I have no idea - but I wouldn't write code that depends on it.

    Relying on String interning is usually a sign of taking performance
    optimisation beyond the point where others are able to make sense
    of your code.
    --
    __________
    |im |yler http://timtyler.org/
     
    Tim Tyler, Sep 8, 2003
    #3
  4. Roedy Green

    Roedy Green Guest

    On Mon, 8 Sep 2003 13:57:21 GMT, Tim Tyler <> wrote or
    quoted :

    >Relying on String interning is usually a sign of taking performance
    >optimisation beyond the point where others are able to make sense
    >of your code.


    People use String interning unconsciously and get away with it
    comparing Strings that come from String literals. All of a sudden
    this code breaks when they get them from a different source. This is
    why I decided to make my MultiProperties intern by default, since it
    reap laces hard coded static final literals.

    All code that takes advantage of string interning clearly has to be
    documented, but it is not rocket science. The only thing you have to
    document is where you relied on == rather than equals and which
    strings have to be interned.

    It has two advantages, space saving when you have many objects
    pointing to the same string, and faster comparisons of long strings.
    You can do a quick equality test.
    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Sep 8, 2003
    #4
  5. Roedy Green

    Tim Tyler Guest

    Roedy Green <> wrote:

    [String interning]

    : It has two advantages, space saving when you have many objects
    : pointing to the same string, and faster comparisons of long strings.
    : You can do a quick equality test.

    Saving space is an advantage of the compiler performing interning.

    It is not an advantage to using "==" rather than ".equals(" for
    string comparisons.

    As you note, this latter practice has some associated dangers.

    Unless you are doing performance optimisations, I reckon there's a good
    case to be made for using a lint tool to warn you whenever "==" is used
    with a String.

    That will catch most of the problems before they happen.
    --
    __________
    |im |yler http://timtyler.org/
     
    Tim Tyler, Sep 10, 2003
    #5
  6. Roedy Green

    Chris Uppal Guest

    Tim Tyler wrote:

    > Unless you are doing performance optimisations, I reckon there's a
    > good case to be made for using a lint tool to warn you whenever "=="
    > is used with a String.


    Maybe not for when comparing two String valued variables, but certainly for any
    code like:

    if (someString == "Hello")
    {
    ...

    The chance of that being correct and viable code must be about 0.0

    This string interning thing is a real mess-up IMO. It'd have been better if
    the language design had required the compiler/runtime to produce a *different*
    String object for each string literal (or String valued compile-time
    expression).

    -- chris
     
    Chris Uppal, Sep 10, 2003
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UG9udGlNYXg=?=

    ArrayList of ArrayLists: How to implement IEnumerable

    =?Utf-8?B?UG9udGlNYXg=?=, Jul 5, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    432
    =?Utf-8?B?UG9udGlNYXg=?=
    Jul 5, 2004
  2. Jim Bancroft
    Replies:
    3
    Views:
    1,882
    Bob Weiner
    May 2, 2005
  3. martin1976

    serialising JLists

    martin1976, Dec 19, 2006, in forum: Java
    Replies:
    4
    Views:
    579
    Andrew Thompson
    Dec 19, 2006
  4. Roedy Green

    Serialising Enums

    Roedy Green, Aug 20, 2009, in forum: Java
    Replies:
    11
    Views:
    585
    Roedy Green
    Aug 21, 2009
  5. Pete Hearn

    serialising parameters manually

    Pete Hearn, Jan 2, 2005, in forum: ASP .Net Web Services
    Replies:
    2
    Views:
    114
    Pete Hearn
    Jan 8, 2005
Loading...

Share This Page