From f7331764ac22d3c25838be057835b79ef7ceaadd Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Mon, 3 Dec 2018 17:46:04 +0100 Subject: 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 --- Transceiver52M/signalVector.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'Transceiver52M/signalVector.cpp') diff --git a/Transceiver52M/signalVector.cpp b/Transceiver52M/signalVector.cpp index fc8157e..710eda5 100644 --- a/Transceiver52M/signalVector.cpp +++ b/Transceiver52M/signalVector.cpp @@ -1,20 +1,20 @@ #include "signalVector.h" -signalVector::signalVector(size_t size) - : Vector(size), +signalVector::signalVector(size_t size, vector_alloc_func wAllocFunc, vector_free_func wFreeFunc) + : Vector(size, wAllocFunc, wFreeFunc), real(false), aligned(false), symmetry(NONE) { } -signalVector::signalVector(size_t size, size_t start) - : Vector(size + start), +signalVector::signalVector(size_t size, size_t start, vector_alloc_func wAllocFunc, vector_free_func wFreeFunc) + : Vector(size + start, wAllocFunc, wFreeFunc), real(false), aligned(false), symmetry(NONE) { mStart = mData + start; } -signalVector::signalVector(complex *data, size_t start, size_t span) - : Vector(NULL, data + start, data + start + span), +signalVector::signalVector(complex *data, size_t start, size_t span, vector_alloc_func wAllocFunc, vector_free_func wFreeFunc) + : Vector(data, data + start, data + start + span, wAllocFunc, wFreeFunc), real(false), aligned(false), symmetry(NONE) { } -- cgit v1.2.3