Skip to content

Commit 5ac5a12

Browse files
committed
Reduce memory copying
1 parent 6124e8e commit 5ac5a12

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

Source/Plugins/SpikeSorter/SpikeSortBoxes.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ void SpikeSortBoxes::projectOnPrincipalComponents(SorterSpikePtr so)
884884
bPCAJobSubmitted = true;
885885
bRePCA = false;
886886
// submit a new job to compute the spike buffer.
887-
PCAjob job(spikeBuffer,pc1,pc2, &pc1min, &pc2min, &pc1max, &pc2max, bPCAjobFinished);
887+
PCAJobPtr job = new PCAjob(spikeBuffer,pc1,pc2, &pc1min, &pc2min, &pc1max, &pc2max, bPCAjobFinished);
888888
computingThread->addPCAjob(job);
889889
}
890890
}
@@ -2140,11 +2140,11 @@ void PCAjob::computeSVD()
21402140
/**********************/
21412141

21422142

2143-
void PCAcomputingThread::addPCAjob(PCAjob job)
2143+
void PCAcomputingThread::addPCAjob(PCAJobPtr job)
21442144
{
21452145
{
21462146
ScopedLock critical(lock);
2147-
jobs.push(job);
2147+
jobs.add(job);
21482148
}
21492149

21502150
if (!isThreadRunning())
@@ -2158,19 +2158,19 @@ void PCAcomputingThread::run()
21582158
while (jobs.size() > 0)
21592159
{
21602160
lock.enter();
2161-
PCAjob J = jobs.front();
2162-
jobs.pop();
2161+
PCAJobPtr J = jobs.removeAndReturn(0);
2162+
if (J == nullptr) continue;
21632163
lock.exit();
21642164
// compute PCA
21652165
// 1. Compute Covariance matrix
21662166
// 2. Apply SVD on covariance matrix
21672167
// 3. Extract the two principal components corresponding to the largest singular values
21682168

2169-
J.computeCov();
2170-
J.computeSVD();
2169+
J->computeCov();
2170+
J->computeSVD();
21712171

21722172
// 4. Report to the spike sorting electrode that PCA is finished
2173-
J.reportDone = true;
2173+
J->reportDone = true;
21742174
}
21752175
}
21762176

Source/Plugins/SpikeSorter/SpikeSortBoxes.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class PCAjob
177177
public:
178178
PCAjob();
179179
};*/
180-
class PCAjob
180+
class PCAjob : public ReferenceCountedObject
181181
{
182182
public:
183183
PCAjob(SorterSpikeArray& _spikes, float* _pc1, float* _pc2,
@@ -197,6 +197,8 @@ class PCAjob
197197
int dim;
198198
};
199199

200+
typedef ReferenceCountedObjectPtr<PCAjob> PCAJobPtr;
201+
typedef ReferenceCountedArray<PCAjob, CriticalSection> PCAJobArray;
200202

201203
class cPolygon
202204
{
@@ -214,10 +216,10 @@ class PCAcomputingThread : juce::Thread
214216
public:
215217
PCAcomputingThread();
216218
void run(); // computes PCA on waveforms
217-
void addPCAjob(PCAjob job);
219+
void addPCAjob(PCAJobPtr job);
218220

219221
private:
220-
std::queue<PCAjob> jobs;
222+
PCAJobArray jobs;
221223
CriticalSection lock;
222224
};
223225

0 commit comments

Comments
 (0)