Use a packet buffer pool to reduce memory pressure

This commit is contained in:
Cameron Gutman
2013-10-29 21:39:57 -04:00
parent e6af9df142
commit e5126ebe01
4 changed files with 53 additions and 29 deletions
@@ -0,0 +1,30 @@
package com.limelight.nvstream.av;
import java.util.LinkedList;
public class AvBufferPool {
private LinkedList<byte[]> bufferList = new LinkedList<byte[]>();
private int bufferSize;
public AvBufferPool(int size)
{
this.bufferSize = size;
}
public synchronized byte[] allocate()
{
if (bufferList.isEmpty())
{
return new byte[bufferSize];
}
else
{
return bufferList.removeFirst();
}
}
public synchronized void free(byte[] buffer)
{
bufferList.addFirst(buffer);
}
}