diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2017-12-11 15:07:18 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2017-12-11 15:07:18 +0100 |
commit | 1087a7f4ad8bb1bc9bf4472bf2734b0e4929e7d1 (patch) | |
tree | 639e403dfe0bce5c2714274d19f540223e072def /src | |
parent | 1ed50fe16d749ac3a841650c4054d137b9cf7a10 (diff) | |
download | dabmod-1087a7f4ad8bb1bc9bf4472bf2734b0e4929e7d1.tar.gz dabmod-1087a7f4ad8bb1bc9bf4472bf2734b0e4929e7d1.tar.bz2 dabmod-1087a7f4ad8bb1bc9bf4472bf2734b0e4929e7d1.zip |
Remove references to malloc.h and use posix_memalign
Diffstat (limited to 'src')
-rw-r--r-- | src/Buffer.cpp | 12 | ||||
-rw-r--r-- | src/DabMod.cpp | 7 | ||||
-rw-r--r-- | src/Flowgraph.cpp | 6 | ||||
-rw-r--r-- | src/FormatConverter.cpp | 1 | ||||
-rw-r--r-- | src/FrequencyInterleaver.cpp | 8 | ||||
-rw-r--r-- | src/Resampler.cpp | 7 |
6 files changed, 15 insertions, 26 deletions
diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 8631c42..6b14561 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -30,13 +30,6 @@ #include <stdlib.h> #include <string.h> -#include <malloc.h> -#if HAVE_DECL__MM_MALLOC -# include <mm_malloc.h> -#else -# define memalign(a, b) malloc(b) -#endif - Buffer::Buffer(size_t len, const void *data) @@ -92,7 +85,10 @@ void Buffer::setLength(size_t len) void *tmp = data; /* Align to 32-byte boundary for AVX. */ - data = memalign(32, len); + const int ret = posix_memalign(&data, 32, len); + if (ret != 0) { + throw std::runtime_error("memory allocation failed: " + std::to_string(ret)); + } if (tmp != NULL) { memcpy(data, tmp, this->len); diff --git a/src/DabMod.cpp b/src/DabMod.cpp index af3adde..1625a82 100644 --- a/src/DabMod.cpp +++ b/src/DabMod.cpp @@ -64,13 +64,6 @@ # include <netinet/in.h> #endif -#if HAVE_DECL__MM_MALLOC -# include <mm_malloc.h> -#else -# define memalign(a, b) malloc(b) -#endif - - /* UHD requires the input I and Q samples to be in the interval * [-1.0,1.0], otherwise they get truncated, which creates very * wide-spectrum spikes. Depending on the Transmission Mode, the diff --git a/src/Flowgraph.cpp b/src/Flowgraph.cpp index 6ee7b81..4870534 100644 --- a/src/Flowgraph.cpp +++ b/src/Flowgraph.cpp @@ -29,12 +29,6 @@ #include <memory> #include <algorithm> #include <sstream> - -#if HAVE_DECL__MM_MALLOC -# include <mm_malloc.h> -#else -# define memalign(a, b) malloc(b) -#endif #include <sys/types.h> #include <stdexcept> #include <assert.h> diff --git a/src/FormatConverter.cpp b/src/FormatConverter.cpp index 6826972..60c0545 100644 --- a/src/FormatConverter.cpp +++ b/src/FormatConverter.cpp @@ -29,7 +29,6 @@ #include "FormatConverter.h" #include "PcDebug.h" -#include <malloc.h> #include <sys/types.h> #include <string.h> #include <stdexcept> diff --git a/src/FrequencyInterleaver.cpp b/src/FrequencyInterleaver.cpp index 29d54bb..bd5042c 100644 --- a/src/FrequencyInterleaver.cpp +++ b/src/FrequencyInterleaver.cpp @@ -24,7 +24,7 @@ #include <stdio.h> #include <stdexcept> -#include <malloc.h> +#include <stdlib.h> #include <complex> typedef std::complex<float> complexf; @@ -68,7 +68,11 @@ FrequencyInterleaver::FrequencyInterleaver(size_t mode) : break; } - d_indexes = (size_t*)memalign(16, d_carriers * sizeof(size_t)); + const int ret = posix_memalign((void**)(&d_indexes), 16, d_carriers * sizeof(size_t)); + if (ret != 0) { + throw std::runtime_error("memory allocation failed: " + std::to_string(ret)); + } + size_t* index = d_indexes; size_t perm = 0; PDEBUG("i: %4u, R: %4u\n", 0, 0); diff --git a/src/Resampler.cpp b/src/Resampler.cpp index 8069a61..2be753e 100644 --- a/src/Resampler.cpp +++ b/src/Resampler.cpp @@ -27,7 +27,7 @@ #include "Resampler.h" #include "PcDebug.h" -#include <malloc.h> +#include <stdlib.h> #include <sys/types.h> #include <string.h> #include <stdexcept> @@ -81,7 +81,10 @@ Resampler::Resampler(size_t inputRate, size_t outputRate, size_t resolution) : myFactor = 1.0f / myFftSizeOut * outputRate / inputRate; } - myWindow = (float*)memalign(16, myFftSizeIn * sizeof(float)); + const int ret = posix_memalign((void**)(&myWindow), 16, myFftSizeIn * sizeof(float)); + if (ret != 0) { + throw std::runtime_error("memory allocation failed: " + std::to_string(ret)); + } for (size_t i = 0; i < myFftSizeIn; ++i) { myWindow[i] = (float)(0.5 * (1.0 - cos(2.0 * M_PI * i / (myFftSizeIn - 1)))); PDEBUG("Window[%zu] = %f\n", i, myWindow[i]); |