From: Michael G. <mic...@gr...> - 2000-10-03 11:17:49
|
Raimar wrote: > On Mon, Oct 02, 2000 at 11:21:21PM +0200, Ulrich Kuhn wrote: > > yOn Mon, 2 Oct 2000, Michael Grundel wrote: > > > > > > A few littleties: > > > > For memory's sake and as it is my job :-) I recommend the following patch > > > > for DataTypeInfoForOneTurn.java: > > > > > > > > 27,28c27,28 > > > > < data = new int[FreecivConstants.MAX_NUM_PLAYERS]; > > > > < defined = new boolean[FreecivConstants.MAX_NUM_PLAYERS]; > > > > --- > > > > > data = new int[4]; > > > > > defined = new boolean[4]; > > > > 44a45 > > > > > if (player >= data.length) grow(Math.max(data.length*2, player)); > > > ^^^ ^^^^^^^^^^^^^ > > > We should be careful not to make it larger than FreecivConstants.MAX_NUM_PLAYERS > > > by doubling. > > > Could this happen or did I miss something? > > As Ulrich mentions below currently this can not happen. However there is no > harm if data is larger than FreecivConstants.MAX_NUM_PLAYERS. I thought the whole point of this was to save space? Would a doubling to 64 not waste a lot of space? > DataTypeInfoForOneTurn doesn't have enough information to check for the > validity of a given playernumber. However it can test if the value was set > previously. > > > Since MAX_NUM_PLAYERS is 32 this can not happen: 4 -> 8 -> 16 -> 32 > > So the highest player number will be 31 and that fits in an array with 32 > > places. IMHO this is no valid argument. In fact it only works if MAX_NUM_PLAYERS is 2^x. I think we should not make such assumptions. It depends on freeciv and could well be increased in the future (to a non 2^x value). Lets say it is increased to 40 in freeciv, we would get: 4 -> 8 -> 16 -> 32 -> 64. Since the whole purpose of this is to save some (small amount) of memory, I believe this should be fixed (if it is done at all). A possible solution: if (player >= data.length) grow(Math.min(Math.max(data.length*2, player), FreecivConstants.MAX_NUM_PLAYERS); Michael -- eMail: mic...@gr... PGP key available on request |