WIP optimization of object allocation and pools. There's currently a double free on the AvByteBufferDescriptor that I'm trying to track down.

This commit is contained in:
Cameron Gutman
2013-11-21 12:24:45 -05:00
parent c42d40b8f6
commit 7951c0fa13
12 changed files with 213 additions and 90 deletions
@@ -1,9 +1,9 @@
package com.limelight.nvstream.av;
import java.util.LinkedList;
import java.util.concurrent.ConcurrentLinkedQueue;
public class AvShortBufferPool {
private LinkedList<short[]> bufferList = new LinkedList<short[]>();
private ConcurrentLinkedQueue<short[]> bufferList = new ConcurrentLinkedQueue<short[]>();
private int bufferSize;
public AvShortBufferPool(int size)
@@ -11,25 +11,22 @@ public class AvShortBufferPool {
this.bufferSize = size;
}
public synchronized void purge()
public void purge()
{
this.bufferList = new LinkedList<short[]>();
bufferList.clear();
}
public synchronized short[] allocate()
public short[] allocate()
{
if (bufferList.isEmpty())
{
return new short[bufferSize];
}
else
{
return bufferList.removeFirst();
short[] buff = bufferList.poll();
if (buff == null) {
buff = new short[bufferSize];
}
return buff;
}
public synchronized void free(short[] buffer)
public void free(short[] buffer)
{
bufferList.addFirst(buffer);
bufferList.add(buffer);
}
}