diff options
author | Pau Espin Pedrol <pespin@sysmocom.de> | 2018-12-03 17:46:04 +0100 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2018-12-05 19:41:34 +0000 |
commit | f7331764ac22d3c25838be057835b79ef7ceaadd (patch) | |
tree | fff479bb9fe2eee69484e455b8a9eaa3b11b32d2 /Transceiver52M/arch/common | |
parent | 800c029c709fda37ec1dd37b833ae5decd03ec2c (diff) |
SigProcLib: Improve Vector buffer allocation mess
Original issue: In order to use SSE instructions, 16-byte aligned memory
chunks are needed, and C++ version < C++11 doesn't provide for a native
new/delete store. For that reason, memalign() must be used in the
implementation of convolve_h_alloc() for some buffers.
On the other side, The C++ code relies on C++ "new T[]" operator to
allocate a chunk of memory containing an array of class instances. As
classes are complex types, they cannot be allocated through C structures
(calling malloc). Experimentally can be seen too that it's unreliable
and the process will crash during startup if malloc() is used and then a
Complex<> deferred from it.
Previous implementation allowed for use of convolve_h_alloc or new[]
based on how the (signal)Vector is called, because then the buffer is
not going to be managed internally. But that's unreliable since resize()
calling resize() on it could use "delete" operator on a malloc'ed
buffer, and end up having a new new[] allocated buffer. It was also
found that some of the callers were actually leaking memory through ASan (because the
buffer is not managed by the Vector instance).
IMHO best option would be to rewrite all this code using C structures
and malloc/free exclusively, since it would make all this cod eeasier to
maintain.
But for now, let's extend the Vector class to allow specifying an
external alloc/free function and let the Vector instance take care of
the ownership of the buffer in all scenarios.
Change-Id: Ie484a4762a7f77fe1b105188ea03a6f025730b82
Diffstat (limited to 'Transceiver52M/arch/common')
-rw-r--r-- | Transceiver52M/arch/common/convolve.h | 2 | ||||
-rw-r--r-- | Transceiver52M/arch/common/convolve_base.c | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/Transceiver52M/arch/common/convolve.h b/Transceiver52M/arch/common/convolve.h index 43db577..095b04c 100644 --- a/Transceiver52M/arch/common/convolve.h +++ b/Transceiver52M/arch/common/convolve.h @@ -1,7 +1,7 @@ #ifndef _CONVOLVE_H_ #define _CONVOLVE_H_ -void *convolve_h_alloc(int num); +void *convolve_h_alloc(size_t num); int convolve_real(const float *x, int x_len, const float *h, int h_len, diff --git a/Transceiver52M/arch/common/convolve_base.c b/Transceiver52M/arch/common/convolve_base.c index 71453a1..2eb7124 100644 --- a/Transceiver52M/arch/common/convolve_base.c +++ b/Transceiver52M/arch/common/convolve_base.c @@ -146,7 +146,7 @@ int base_convolve_complex(const float *x, int x_len, } /* Aligned filter tap allocation */ -void *convolve_h_alloc(int len) +void *convolve_h_alloc(size_t len) { #ifdef HAVE_SSE3 return memalign(16, len * 2 * sizeof(float)); |