Skip to content

Commit 83b1d33

Browse files
committed
Made the datagram factory only create the objects as it needs to.
1 parent 4de31dd commit 83b1d33

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

javasdk/NRSDK/src/com/neuronrobotics/sdk/common/BowlerDatagramFactory.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,32 +60,37 @@ private static synchronized BowlerDatagram getNextPacket(){
6060
//Find the most recent free packet from the pool
6161
for(int i=lastIndex;(i<pool.length && ref==null);i++){
6262
//Log.warning("Checking pool packet "+i);
63+
if(pool[i]==null){
64+
pool[i]=new BowlerDatagram(instance);
65+
freePacket(pool[i]);
66+
}
6367
if(pool[i].isFree()){
6468
lastIndex=i;
6569
ref=pool[i];
6670
}
67-
if(i==pool.length-1){
71+
if(i==pool.length-1 && ref==null){
6872
//loop around since we started at the last index
6973
i=0;
7074
}
71-
if(i==lastIndex-1){
75+
if(i==lastIndex-1 && ref==null){
7276
//looped around, bail
7377
i=pool.length;
7478
}
7579
}
7680
if(ref == null){
7781
//The whole list was search and no free packets were found
78-
BowlerDatagram newPool [ ] = new BowlerDatagram[pool.length];
79-
Log.warning("Resetting pool "+newPool.length);
80-
81-
//Adding the new packets
82-
for(int i=0;i<newPool.length;i++){
83-
newPool[i] = new BowlerDatagram(instance);
84-
freePacket(newPool[i]);
85-
if(ref==null)
86-
ref=newPool[i];
87-
}
88-
pool = newPool;
82+
pool= new BowlerDatagram[(int) ((float)pool.length)];
83+
Log.warning("Resetting pool "+pool.length);
84+
pool[0]= new BowlerDatagram(instance);
85+
ref=pool[0];
86+
// //Adding the new packets
87+
// for(int i=0;i<newPool.length;i++){
88+
// newPool[i] = new BowlerDatagram(instance);
89+
// freePacket(newPool[i]);
90+
// if(ref==null)
91+
// ref=newPool[i];
92+
// }
93+
// pool = newPool;
8994
}
9095
//old pool data given to the GC
9196
ref.setFree(false,instance);

0 commit comments

Comments
 (0)