commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Colebourne" <scolebou...@btopenworld.com>
Subject Re: [lang] Pooled and mutable numbers.
Date Tue, 11 Mar 2003 23:14:00 GMT
> 1) A mechanism for pooling Integers, Floats, Doubles, etc. as they are
> created, to conserve memory.  For example, instead of having:
>
> new Integer(1)
>
> scattered throughout the code, there could be a NumberPool class which
> would allow:
>
> NumberFactory.createInteger(1)
>
> the values would be cached, and could use a WeakHashMap or something
> similar to manage the cache.

I believe that I added a number of constants to NumberUtils for the low
numbered constants. Adding such a method to NumberUtils might make sense,
however, I'm less convinced about the WeakHashMap idea - you would need to
wrap the int in an Integer object to use a WeakHashMap which defeats the
purpose.

One strategy would be to have an Integer[], maybe size 1000, lazily
instantiated. If the int value requested is larger than this then it is
created new each time. If less than 1000 then it could be returned directly
from the array.

Whether it is really beneficial though is questionable. Really this is
something that should be in the JDK.


> 2) Mutable versions of these same Objects.  There could be an interface
> named Mutable with a setValue(Object) method, which could have
> extensions for MutableInteger, MutableFloat, and so on.  I saw something
> like this in JBoss and thought it seemed like an interesting idea.

I believe that there is a place for mutable number objects in [lang]. There
would need to be a MutableNumber class that extends Number. Then subclasses
from that.

Stephen



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


Mime
View raw message