squeezing the use of memory  
Author Message
asifkazi





PostPosted: 2003-10-13 6:48:00 Top

java-programmer, squeezing the use of memory Hi,
Qick question about the use of int Vs. the use of short,char,byte
in 'for' loops. Will it affect the memory utilization/performance at all ?
If yes, to what extent, especially considering a program which uses
looping extensively and doesn't need the entire 'int' range.
Generally people just go ahead and use 'int' in loops...
Awaiting your thoughts,
Asif
 
ak





PostPosted: 2003-10-13 6:55:00 Top

java-programmer >> squeezing the use of memory no, it may be time consuming thing because of promoting byte to int.

"Asif Kazi" <email***@***.com> schrieb im Newsbeitrag
news:email***@***.com...
> Hi,
> Qick question about the use of int Vs. the use of short,char,byte
> in 'for' loops. Will it affect the memory utilization/performance at all ?
> If yes, to what extent, especially considering a program which uses
> looping extensively and doesn't need the entire 'int' range.
> Generally people just go ahead and use 'int' in loops...
> Awaiting your thoughts,
> Asif


 
VisionSet





PostPosted: 2003-10-13 6:56:00 Top

java-programmer >> squeezing the use of memory "Asif Kazi" <email***@***.com> wrote in message
news:email***@***.com...
> Hi,
> Qick question about the use of int Vs. the use of short,char,byte
> in 'for' loops. Will it affect the memory utilization/performance at all ?
> If yes, to what extent, especially considering a program which uses
> looping extensively and doesn't need the entire 'int' range.
> Generally people just go ahead and use 'int' in loops...
> Awaiting your thoughts,

AFAIK
If there is a memory issue, ie large arrays etc, use the narrowest primative
type.
However consider that int is faster on most platforms since it is 32 bit and
so is the processor.

That may be over simplistic and I'd be interested in further comments also.

--
Mike W

Sun Certified Programmer for the Java 2 Platform 1.4 :-)
Self congratulation for a limited time only ;-)


 
 
Brian S O'Neill





PostPosted: 2003-10-13 6:57:00 Top

java-programmer >> squeezing the use of memory Whenever Java is running on a 32-bit platform, (which is usually the
case), then short, byte, and char are actully represented internally as
32-bit ints. You won't see any memory savings except in arrays.

As for performance in loops, int is prefered. Using a smaller type is
not native to the platform, and there may be a cost to keeping the value
in the right range and having to do any sign extension upon conversion.

Asif Kazi wrote:
> Hi,
> Qick question about the use of int Vs. the use of short,char,byte
> in 'for' loops. Will it affect the memory utilization/performance at all ?
> If yes, to what extent, especially considering a program which uses
> looping extensively and doesn't need the entire 'int' range.
> Generally people just go ahead and use 'int' in loops...
> Awaiting your thoughts,
> Asif

 
 
Jon Skeet





PostPosted: 2003-10-13 19:52:00 Top

java-programmer >> squeezing the use of memory Brian S O'Neill <email***@***.com> wrote:
> Whenever Java is running on a 32-bit platform, (which is usually the
> case), then short, byte, and char are actully represented internally as
> 32-bit ints. You won't see any memory savings except in arrays.

That's not true. It was in Sun's JVM before 1.4, but as of 1.4, you can
get a space saving. If you have an object with 1000 byte fields in it,
that will take up just over 1000 bytes. If you have an object with 1000
int fields in it, that will take up just over 4000 bytes.

--
Jon Skeet - <email***@***.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too