commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Gregory <ggreg...@seagullsw.com>
Subject RE: [lang] ObjectUtils interner?
Date Wed, 12 Mar 2003 17:06:20 GMT
The test provide some interesting data but as Strings support being
intern'ed in the JRE (String.intern()), using Strings as an example is
probably not the best choice unless you want to pool String Objects outside
of the String class intern pool.

Gary

-----Original Message-----
From: Juozas Baliuka [mailto:baliuka@mwm.lt]
Sent: Wednesday, March 12, 2003 8:28 AM
To: Jakarta Commons Developers List
Subject: Re: [lang] ObjectUtils interner?


trivial test:


       final int iterations = 100000;
       long time = System.currentTimeMillis();

       for(int i =0; i< iterations ; i++){
          String s =  new String("A");
       }

       System.out.println( "inren " + (System.currentTimeMillis() - time) );

       time = System.currentTimeMillis();
       for(int i =0; i< iterations ; i++){
           char s[] = new char[]{'A'};
       }

       System.out.println( "new " + (System.currentTimeMillis() - time) );


output:

inren 140
new 21

String pooling doe's not helps for me, but possible this test is wrong .

----- Original Message -----
From: "Gary Gregory" <ggregory@seagullsw.com>
To: "'Jakarta Commons Developers List'" <commons-dev@jakarta.apache.org>
Sent: Wednesday, March 12, 2003 3:35 PM
Subject: RE: [lang] ObjectUtils interner?


> >1) A mechanism for pooling Integers, Floats, Doubles, etc. as they are
> >created, to conserve memory.
>
> As someone else noted, objects created by running this util code could
itelf
> create extra objects that would nullify benefits of such memory savings.
In
> my work I try not to spend time providing performance/memory improvements
> until I have measured a specific bottleneck (with JProbe or simply
> System.currentTimeMillis()). Yes, in theory, something like this could be
> quite useful and I can imagine scenarios where gobs of Integers are needed
> but I would personally not bother until I have proven to myself that my
> bottleneck is creating Integers (or Floats, or whatever).
>
> Furthermore, doesn't an Object "interner" sounds like it belongs in Pool
> more than in Lang?
>
> Gary
>
> -----Original Message-----
> From: Stephen Colebourne [mailto:scolebourne@btopenworld.com]
> Sent: Tuesday, March 11, 2003 3:57 PM
> To: Jakarta Commons Developers List
> Subject: Re: [lang] ObjectUtils interner?
>
>
> Any views on this one?
>
> It seems like a sensible addition to ObectUtils. (Although I'm not sure of
> the exact use it would be. Hmmm)
>
> Stephen
>
> ----- Original Message -----
> From: "Rich Dougherty" <rich@rd.gen.nz>
> To: "Jakarta Commons Developers List" <commons-dev@jakarta.apache.org>
> Sent: Tuesday, March 11, 2003 11:31 PM
> Subject: Re: [lang] Pooled and mutable numbers.
>
> >1) A mechanism for pooling Integers, Floats, Doubles, etc. as they are
> >created, to conserve memory.  For example, instead of having:
>
> Here's a fun little class. It is inspired by the String.intern() method.
>
> import java.util.WeakHashMap;
> import java.util.Map;
>
> public class Interner {
>
>      private Map internedObjects = new WeakHashMap();
>
>      public Interner() {
>      }
>
>      public Object intern(Object object) {
>          Object internedObject = internedObjects.get(object);
>          if (internedObject == null) {
>              internedObjects.put(object, object);
>              return object;
>          } else {
>              return internedObject;
>          }
>      }
>
> }
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message