Probable fix of memory leak

This commit is contained in:
Anne de Jong 2022-01-13 13:59:35 +01:00
parent 8fee46a41f
commit 4339ecdbc0
2 changed files with 164 additions and 136 deletions

View File

@ -36,20 +36,40 @@ in a sister repository in a later stage.
If you have any question(s), please feel free to contact us: info@ascee.nl. If you have any question(s), please feel free to contact us: info@ascee.nl.
## Installation # Building from source
### Compilation ## Dependencies
#### Archlinux Optional dependencies, which can be turned ON/OFF using CMake:
- Build tools, including [http://cmake.org](CMake).
- FFTW (For really fast FFT's)
- libUlDAQ, for the Measurement Computing DT9837A USB DAQ box
- GNU Autotools, for compiling libUlDAQ
- RtAudio, for Audio DAQ backends
- Cython, for wrapping the C-code to Python.
- The following Python packages need also be available:
- `Scipy` (which includes Numpy). Install with `sudo apt install
python3-scipy`, or `pacman -S scipy`.
- `appdirs`, which can be grabbed from [https://pypi.org](Pypi)
## Installation of dependencies
## Compilation of LASP
### Archlinux
Compiling the code on Archlinux requires the following packages to be available: Compiling the code on Archlinux requires the following packages to be available:
- openblas-lapack (AUR) - openblas-lapack (AUR)
- Python 3.7 - Python>=3.7
- Numpy (Python-numpy) - Numpy (Python-numpy)
- Cython - Cython
#### Ubuntu / Linux Mint ### Ubuntu / Linux Mint
*Only tested with Linux Mint 18.04*, we require the following packages for *Only tested with Linux Mint 18.04*, we require the following packages for
compilation: compilation:
@ -62,17 +82,3 @@ compilation:
- libopenblas-base - libopenblas-base
- libopenblas-dev - libopenblas-dev
#### Windows specific
Tested using a Anacond / Miniconda Python environment. Please first run the following command:
`conda install fftw`
in case you want the *FFTW* fft backend.
### Dependencies
#### Ubuntu / Linux Mint
*Only tested with Linux Mint 18.04*. The following Dependencies are required
for Ubuntu:

View File

@ -40,7 +40,7 @@ class DT9837A : public Daq {
us nFramesPerBlock; us nFramesPerBlock;
public: public:
DT9837A(const DeviceInfo &devinfo, const DaqConfiguration &config) DT9837A(const DeviceInfo &devinfo, const DaqConfiguration &config)
: Daq(devinfo, config) { : Daq(devinfo, config) {
@ -203,6 +203,40 @@ public:
friend void threadfcn(DT9837A *); friend void threadfcn(DT9837A *);
}; };
/**
* @brief Create an empty buffer and fill it with zeros.
*
* @param size The number of elements in the array
*
* @return Pointer to the array
*/
static double* createZeroBuffer(size_t size) {
double* buf = static_cast<double *>(
malloc(sizeof(double) * size));
for (us sample = 0; sample < size; sample++) {
buf[sample] = 0;
}
return buf;
}
/**
* @brief Copy samples from one linear array to the next.
*
* @param[in] from Buffer to copy from
* @param[out] to Buffer to copy to
* @param startFrom The position to start in the from-buffer
* @param startTo The position to start in the to-buffer
* @param N The number of samples to copy.
*/
static inline void copySamples(double* from,double* to,
const us startFrom,const us startTo,const us N) {
for (us sample = 0; sample < N; sample++) {
to[startTo + sample] = from[startFrom + sample];
}
}
void threadfcn(DT9837A *td) { void threadfcn(DT9837A *td) {
std::cerr << "Starting DAQ Thread fcn" << endl; std::cerr << "Starting DAQ Thread fcn" << endl;
@ -362,22 +396,16 @@ void threadfcn(DT9837A *td) {
if (!botoutenqueued) { if (!botoutenqueued) {
/* cerr << "Copying output buffer to bottom" << endl; */ /* cerr << "Copying output buffer to bottom" << endl; */
double *bufcpy; double *bufcpy;
assert(nenoutchannels > 0);
if (!outqueue->empty()) { if (!outqueue->empty()) {
bufcpy = (double *)outqueue->dequeue(); bufcpy = (double *)outqueue->dequeue();
} else { } else {
cerr << "******* WARNING: OUTPUTQUEUE UNDERFLOW, FILLING SIGNAL " cerr << "******* WARNING: OUTPUTQUEUE UNDERFLOW, FILLING SIGNAL "
"QUEUE WITH ZEROS ***********" "QUEUE WITH ZEROS ***********"
<< endl; << endl;
bufcpy = static_cast<double *>( bufcpy = createZeroBuffer(nFramesPerBlock*nenoutchannels);
malloc(sizeof(double) * nFramesPerBlock * nenoutchannels));
for (us sample = 0; sample < nFramesPerBlock; sample++) {
bufcpy[sample] = 0;
}
}
assert(nenoutchannels > 0);
for (us sample = 0; sample < nFramesPerBlock; sample++) {
outbuffer[buffer_mid_idx_out + sample] = bufcpy[sample];
} }
copySamples(bufcpy, outbuffer, 0, buffer_mid_idx_out, nFramesPerBlock);
free(bufcpy); free(bufcpy);
botoutenqueued = true; botoutenqueued = true;
} }
@ -386,22 +414,16 @@ void threadfcn(DT9837A *td) {
if (!topoutenqueued) { if (!topoutenqueued) {
/* cerr << "Copying output buffer to top" << endl; */ /* cerr << "Copying output buffer to top" << endl; */
double *bufcpy; double *bufcpy;
assert(nenoutchannels > 0);
if (!outqueue->empty()) { if (!outqueue->empty()) {
bufcpy = (double *)outqueue->dequeue(); bufcpy = (double *)outqueue->dequeue();
} else { } else {
cerr << "******* WARNING: OUTPUTQUEUE UNDERFLOW, FILLING SIGNAL " cerr << "******* WARNING: OUTPUTQUEUE UNDERFLOW, FILLING SIGNAL "
"QUEUE WITH ZEROS ***********" "QUEUE WITH ZEROS ***********"
<< endl; << endl;
bufcpy = static_cast<double *>( bufcpy = createZeroBuffer(nFramesPerBlock*nenoutchannels);
malloc(sizeof(double) * nFramesPerBlock * nenoutchannels));
for (us sample = 0; sample < nFramesPerBlock; sample++) {
bufcpy[sample] = 0;
}
}
assert(nenoutchannels > 0);
for (us sample = 0; sample < nFramesPerBlock; sample++) {
outbuffer[sample] = bufcpy[sample];
} }
copySamples(bufcpy, outbuffer, 0, 0, nFramesPerBlock);
free(bufcpy); free(bufcpy);
topoutenqueued = true; topoutenqueued = true;
} }