i asked something about java optimization before, but i gave a very poor
example... leading to not much help... so here is a better situation.
i have a Map, and i'm constantly picking entries from random from this
map.
in one method, i only use the map.
in another method, i use an array of keys from the map, stored seperately.
method a (only the map):
Map myMap = //initialize map
Object randObj;
// begin loop
randObj = myMap.keySet().toArray()[(int)Math.floor(Math.random() *
myMap.size())];
so, as you can see, in method a i constantly re-acquire the array of
keys... but reduce the clutter.
method b:
Map myMap = //initialize map
Object[] keyArray = myMap.keySet().toArray();
// begin loop
randObj = myMap.get(keyArray[(int)Math.floor(Math.random() *
keyArray.length)]);
the only change then is one single array that has a name.
what i'm wondering is:
does the compiler or runtime environment do any optimizations such that
method a is the same (or better maybe) than method b?
while i know the call stack will be one shorter in method b, i'm really
curious about whether or not method a constantly allocates and frees up
memory for the array.
does anyone know where i can find out about these sorts of issues, or can
anyone clear this example out for me?
thanks much,
murat
--
Murat Tasan
mx**@po.cwru.edu
ta***@eecs.cwru.edu
mu*********@cwru.edu
http://genomics.cwru.edu