memory optimization
This commit is contained in:
parent
d571f5328b
commit
9fbe334d8a
1 changed files with 862 additions and 862 deletions
48
src/util.h
48
src/util.h
|
@ -259,44 +259,44 @@ public:
|
||||||
CVector<TData>(),
|
CVector<TData>(),
|
||||||
iCurIdx ( 0 ),
|
iCurIdx ( 0 ),
|
||||||
iNorm ( 0 ),
|
iNorm ( 0 ),
|
||||||
tCurAvResult ( TData ( 0 ) ),
|
dCurAvResult ( 0 ),
|
||||||
tNoDataResult ( TData ( 0 ) ) {}
|
dNoDataResult ( 0 ) {}
|
||||||
|
|
||||||
void Add ( const TData tNewD );
|
void Add ( const TData tNewD );
|
||||||
|
|
||||||
void Init ( const int iNewSize,
|
void Init ( const int iNewSize,
|
||||||
const TData tNNoDRes = TData ( 0 ) );
|
const double dNNoDRes = 0 );
|
||||||
|
|
||||||
void Reset();
|
void Reset();
|
||||||
|
|
||||||
inline TData GetAverage()
|
inline double GetAverage()
|
||||||
{
|
{
|
||||||
if ( this->iNorm == 0 )
|
if ( this->iNorm == 0 )
|
||||||
{
|
{
|
||||||
return tNoDataResult;
|
return dNoDataResult;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return tCurAvResult / this->iNorm;
|
return dCurAvResult / this->iNorm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsInitialized() { return ( this->iNorm == this->iVectorSize ); }
|
bool IsInitialized() { return ( this->iNorm == this->iVectorSize ); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int iCurIdx;
|
int iCurIdx;
|
||||||
int iNorm;
|
int iNorm;
|
||||||
TData tCurAvResult;
|
double dCurAvResult;
|
||||||
TData tNoDataResult;
|
double dNoDataResult;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class TData> void CMovingAv<TData>::Init ( const int iNewSize,
|
template<class TData> void CMovingAv<TData>::Init ( const int iNewSize,
|
||||||
const TData tNNoDRes )
|
const double dNNoDRes )
|
||||||
{
|
{
|
||||||
iNorm = 0;
|
iNorm = 0;
|
||||||
iCurIdx = 0;
|
iCurIdx = 0;
|
||||||
tCurAvResult = TData ( 0 ); // only for scalars!
|
dCurAvResult = 0; // only for scalars!
|
||||||
tNoDataResult = tNNoDRes;
|
dNoDataResult = dNNoDRes;
|
||||||
CVector<TData>::Init ( iNewSize );
|
CVector<TData>::Init ( iNewSize );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,7 +304,7 @@ template<class TData> void CMovingAv<TData>::Reset()
|
||||||
{
|
{
|
||||||
iNorm = 0;
|
iNorm = 0;
|
||||||
iCurIdx = 0;
|
iCurIdx = 0;
|
||||||
tCurAvResult = TData ( 0 ); // only for scalars!
|
dCurAvResult = 0; // only for scalars!
|
||||||
CVector<TData>::Reset ( TData ( 0 ) );
|
CVector<TData>::Reset ( TData ( 0 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,10 +316,10 @@ template<class TData> void CMovingAv<TData>::Add ( const TData tNewD )
|
||||||
history buffer.
|
history buffer.
|
||||||
*/
|
*/
|
||||||
// subtract oldest value
|
// subtract oldest value
|
||||||
tCurAvResult -= this->pData[iCurIdx];
|
dCurAvResult -= this->pData[iCurIdx];
|
||||||
|
|
||||||
// add new value and write in memory
|
// add new value and write in memory
|
||||||
tCurAvResult += tNewD;
|
dCurAvResult += tNewD;
|
||||||
this->pData[iCurIdx] = tNewD;
|
this->pData[iCurIdx] = tNewD;
|
||||||
|
|
||||||
// increase position pointer and test if wrap
|
// increase position pointer and test if wrap
|
||||||
|
@ -814,7 +814,7 @@ public:
|
||||||
{
|
{
|
||||||
// initialize buffer (use "no data result" of 1.0 which stands for the
|
// initialize buffer (use "no data result" of 1.0 which stands for the
|
||||||
// worst error rate possible)
|
// worst error rate possible)
|
||||||
ErrorsMovAvBuf.Init ( iHistoryLength, 1.0f );
|
ErrorsMovAvBuf.Init ( iHistoryLength, 1.0 );
|
||||||
|
|
||||||
bPreviousState = true;
|
bPreviousState = true;
|
||||||
|
|
||||||
|
@ -839,11 +839,11 @@ public:
|
||||||
// add errors as values 0 and 1 to get correct error rate average
|
// add errors as values 0 and 1 to get correct error rate average
|
||||||
if ( bState )
|
if ( bState )
|
||||||
{
|
{
|
||||||
ErrorsMovAvBuf.Add ( 1.0f );
|
ErrorsMovAvBuf.Add ( 1 );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ErrorsMovAvBuf.Add ( 0.0f );
|
ErrorsMovAvBuf.Add ( 0 );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -854,9 +854,9 @@ public:
|
||||||
double GetAverage() { return ErrorsMovAvBuf.GetAverage(); }
|
double GetAverage() { return ErrorsMovAvBuf.GetAverage(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CMovingAv<float> ErrorsMovAvBuf;
|
CMovingAv<char> ErrorsMovAvBuf;
|
||||||
bool bBlockOnDoubleErrors;
|
bool bBlockOnDoubleErrors;
|
||||||
bool bPreviousState;
|
bool bPreviousState;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* !defined ( UTIL_HOIH934256GEKJH98_3_43445KJIUHF1912__INCLUDED_ ) */
|
#endif /* !defined ( UTIL_HOIH934256GEKJH98_3_43445KJIUHF1912__INCLUDED_ ) */
|
||||||
|
|
Loading…
Add table
Reference in a new issue