mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2024-09-20 12:26:57 -04: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>
|
template<class BufferType = ReferenceCounter>
|
||||||
class ReBuffer {
|
class ReBuffer {
|
||||||
|
|
||||||
@ -44,11 +46,23 @@ public:
|
|||||||
BufferType *getBuffer() {
|
BufferType *getBuffer() {
|
||||||
BufferType* buf = NULL;
|
BufferType* buf = NULL;
|
||||||
for (outputBuffersI = outputBuffers.begin(); outputBuffersI != outputBuffers.end(); outputBuffersI++) {
|
for (outputBuffersI = outputBuffers.begin(); outputBuffersI != outputBuffers.end(); outputBuffersI++) {
|
||||||
if ((*outputBuffersI)->getRefCount() <= 0) {
|
if (!buf && (*outputBuffersI)->getRefCount() <= 0) {
|
||||||
return (*outputBuffersI);
|
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();
|
buf = new BufferType();
|
||||||
outputBuffers.push_back(buf);
|
outputBuffers.push_back(buf);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user