mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2024-11-10 06:18:57 -05:00
Automatic ReBuffer<> garbage collection of unused buffers
This commit is contained in:
parent
f4640094b8
commit
847f7a7569
@ -37,6 +37,8 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
#define REBUFFER_GC_LIMIT 100
|
||||
|
||||
template<class BufferType = ReferenceCounter>
|
||||
class ReBuffer {
|
||||
|
||||
@ -44,11 +46,23 @@ public:
|
||||
BufferType *getBuffer() {
|
||||
BufferType* buf = NULL;
|
||||
for (outputBuffersI = outputBuffers.begin(); outputBuffersI != outputBuffers.end(); outputBuffersI++) {
|
||||
if ((*outputBuffersI)->getRefCount() <= 0) {
|
||||
return (*outputBuffersI);
|
||||
if (!buf && (*outputBuffersI)->getRefCount() <= 0) {
|
||||
buf = (*outputBuffersI);
|
||||
(*outputBuffersI)->setRefCount(0);
|
||||
} else if ((*outputBuffersI)->getRefCount() <= 0) {
|
||||
(*outputBuffersI)->decRefCount();
|
||||
}
|
||||
}
|
||||
|
||||
if (buf) {
|
||||
if (outputBuffers.back()->getRefCount() < -REBUFFER_GC_LIMIT) {
|
||||
BufferType *ref = outputBuffers.back();
|
||||
outputBuffers.pop_back();
|
||||
delete ref;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
buf = new BufferType();
|
||||
outputBuffers.push_back(buf);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user