fix issue #19: got rid of jkqtpArrayMalloc(), jkqtpArrayCalloc(), jkqtpArrayFree() (which were a remenant of QuickFit 3 and not really portable or useful)

This commit is contained in:
jkriege2 2019-11-18 16:15:49 +01:00
parent bc1afa7815
commit 307f477626
2 changed files with 6 additions and 75 deletions

View File

@ -59,75 +59,6 @@
/*! \brief malloc() for use herein (aligned on some systems!)
\ingroup jkqtptools_math_array
*/
inline void* jkqtpArrayMalloc(size_t size) {
// std::cout<<"statisticsMalloc("<<size<<")\n";
#ifdef STATISTICS_TOOLS_USE_QFTOOLS_H
return qfMalloc(size);
#else
if (size<=0) return nullptr;
#ifdef __LINUX__
#if !defined(QF_DONT_USE_ALIGNED_MALLOC)
return aligned_alloc(JKQTP_ALIGNMENT_BYTES, size);
#else
return malloc(size);
#endif
#else
#if !defined(QF_DONT_USE_ALIGNED_MALLOC)
return _aligned_malloc(size, JKQTP_ALIGNMENT_BYTES);
#else
return malloc(size);
#endif
#endif
#endif
}
/*! \brief calloc() for use herein (aligned on some systems!)
\ingroup jkqtptools_math_array
*/
inline void* jkqtpArrayCalloc(size_t num, size_t size) {
// std::cout<<"statisticsCalloc("<<num<<", "<<size<<")\n";
#ifdef STATISTICS_TOOLS_USE_QFTOOLS_H
return qfCalloc(num,size);
#else
if (size*size<=0) return nullptr;
void* res=jkqtpArrayMalloc(num*size);
memset(res, 0, num*size);
return res;
#endif
}
/*! \brief free() for use herein (aligned on some systems!)
\ingroup jkqtptools_math_array
*/
inline void jkqtpArrayFree(void* data) {
#ifdef STATISTICS_TOOLS_USE_QFTOOLS_H
qfFree(data);
#else
if (!data) return;
#ifdef __LINUX__
#if !defined(QF_DONT_USE_ALIGNED_MALLOC)
free(data);
#else
free(data);
#endif
#else
#if !defined(QF_DONT_USE_ALIGNED_MALLOC)
_aligned_free(data);
#else
free(data);
#endif
#endif
#endif
}
/*! \brief swap two elements \a l and \a r in an array \a a
\ingroup jkqtptools_math_array
@ -155,13 +86,13 @@ inline void jkqtpArraySwapV(std::vector<T>& a, long long l, long long r){
/*! \brief duplicate an array of data
\ingroup jkqtptools_math_array
\note use jkqtpArrayFree() to free the memory!!!
\note use free() to free the memory!!!
*/
template <class T>
inline T* jkqtpArrayDuplicate(const T* dataIn, long long N) {
// std::cout<<"statisticsDuplicateArray("<<dataIn<<", "<<N<<")\n";
if (N<=0 || !dataIn) return nullptr;
T* out=static_cast<T*>(jkqtpArrayMalloc(N*sizeof(T)));
T* out=static_cast<T*>(malloc(N*sizeof(T)));
if (out) memcpy(out, dataIn, N*sizeof(T));
return out;
}
@ -169,7 +100,7 @@ inline T* jkqtpArrayDuplicate(const T* dataIn, long long N) {
/*! \brief this class ensures that the given pointer is jkqtpArrayFreed when the class is destroyed.
/*! \brief this class ensures that the given pointer is freed when the class is destroyed.
\ingroup jkqtptools_math_array
*/
@ -188,7 +119,7 @@ class JKQTPArrayScopedPointer {
~JKQTPArrayScopedPointer() {
if (pntr) jkqtpArrayFree(pntr);
if (pntr) free(pntr);
}

View File

@ -702,7 +702,7 @@ inline bool jkqtplinalgLinSolve(const T* A, const T* B, long N, long C, T* resul
// v ... ... ... | .....
//
const long msize=N*(N+C);
JKQTPArrayScopedPointer<T> m(static_cast<T*>(jkqtpArrayMalloc(msize*sizeof(T)))); // use scoped pointer to ensure, that m is free'd, when the function is ending
JKQTPArrayScopedPointer<T> m(static_cast<T*>(malloc(msize*sizeof(T)))); // use scoped pointer to ensure, that m is free'd, when the function is ending
for (long l=0; l<N; l++) {
for (long c=0; c<N; c++) { // init left half with matrix A
m[jkqtplinalgMatIndex(l,c,N+C)]=A[jkqtplinalgMatIndex(l,c,N)];
@ -837,7 +837,7 @@ inline T jkqtplinalgMatrixDeterminant(const T* a, long N) {
} else {
det = 0;
for (j1=0;j1<N;j1++) {
JKQTPArrayScopedPointer<T> m(static_cast<T*>(jkqtpArrayCalloc((N-1)*(N-1),sizeof(T *))));
JKQTPArrayScopedPointer<T> m(static_cast<T*>(calloc((N-1)*(N-1),sizeof(T *))));
for (i=1;i<N;i++) {
j2 = 0;