引入缓冲池技术
核心代码,引入缓冲池技术
class CTechnique
{
private:
//1、定义缓冲池
double * m_pdCache1;
double * m_pdCache2;
double * m_pdCache3;
double * m_pdCache4;
double * m_pdCache5;
}
CTechnique::CTechnique( CKData * pKData )
{
//2、初始化缓冲池
m_pdCache1 = NULL;
m_pdCache2 = NULL;
m_pdCache3 = NULL;
m_pdCache4 = NULL;
m_pdCache5 = NULL;
}
void CTechnique::Clear( )
{
//3、清空缓冲池
if( m_pdCache1 )
delete [] m_pdCache1;
if( m_pdCache2 )
delete [] m_pdCache2;
if( m_pdCache3 )
delete [] m_pdCache3;
if( m_pdCache4 )
delete [] m_pdCache4;
if( m_pdCache5 )
delete [] m_pdCache5;
}
// 将计算好的数据保存至缓冲区
BOOL CTechnique::StoreToCache( int nIndex, double * pValue1, double *pValue2, double *pValue3, double * pValue4, double * pValue5 )
{
//4、从缓冲池中存数据
if( pValue1 && m_pdCache1 && m_pbHasCache1 )
{
m_pdCache1[nIndex-m_nIndexStart] = *pValue1;
}
if( pValue2 && m_pdCache2 && m_pbHasCache2 )
{
m_pdCache2[nIndex-m_nIndexStart] = *pValue2;
}
if( pValue3 && m_pdCache3 && m_pbHasCache3 )
{
m_pdCache3[nIndex-m_nIndexStart] = *pValue3;
}
if( pValue4 && m_pdCache4 && m_pbHasCache4 )
{
m_pdCache4[nIndex-m_nIndexStart] = *pValue4;
}
if( pValue5 && m_pdCache5 && m_pbHasCache5 )
{
m_pdCache5[nIndex-m_nIndexStart] = *pValue5;
}
}
BOOL CTechnique::LoadFromCache( int nIndex, double * pValue1, double * pValue2, double * pValue3, double * pValue4, double * pValue5 )
{
//4、从缓冲池中取数据
if( pValue1 )
*pValue1 = m_pdCache1[nIndex-m_nIndexStart];
if( pValue2 )
*pValue2 = m_pdCache2[nIndex-m_nIndexStart];
if( pValue3 )
*pValue3 = m_pdCache3[nIndex-m_nIndexStart];
if( pValue4 )
*pValue4 = m_pdCache4[nIndex-m_nIndexStart];
if( pValue5 )
*pValue5 = m_pdCache5[nIndex-m_nIndexStart];
}