Ticket #66: tracemem.patch

File tracemem.patch, 120.9 KB (added by li@…, 11 years ago)

Patch based on revision 176

  • build/linux/lib/TLibCommon/makefile

     
    5454                        $(OBJ_DIR)/TComSlice.o \
    5555                        $(OBJ_DIR)/TComTrQuant.o \
    5656                        $(OBJ_DIR)/TComYuv.o \
     57                        $(OBJ_DIR)/tool_tracemem.o \
    5758
    5859LIBS                            = -lpthread
    5960
  • build/vc8/TLibCommon_vc8.vcproj

     
    363363                                RelativePath="..\..\source\Lib\TLibCommon\TComYuv.cpp"
    364364                                >
    365365                        </File>
     366                        <File
     367                                RelativePath="..\..\source\Lib\TLibCommon\tool_tracemem.cpp"
     368                                >
     369                        </File>
    366370                </Filter>
    367371                <Filter
    368372                        Name="Header Files"
     
    478482                                >
    479483                        </File>
    480484                        <File
     485                                RelativePath="..\..\source\Lib\TLibCommon\tool_tracemem.h"
     486                                >
     487                        </File>
     488                        <File
    481489                                RelativePath="..\..\source\Lib\TLibCommon\TypeDef.h"
    482490                                >
    483491                        </File>
  • build/vc9/TLibCommon_vc9.vcproj

     
    366366                                RelativePath="..\..\source\Lib\TLibCommon\TComYuv.cpp"
    367367                                >
    368368                        </File>
     369                        <File
     370                                RelativePath="..\..\source\Lib\TLibCommon\tool_tracemem.cpp"
     371                                >
     372                        </File>
    369373                </Filter>
    370374                <Filter
    371375                        Name="Header Files"
     
    481485                                >
    482486                        </File>
    483487                        <File
     488                                RelativePath="..\..\source\Lib\TLibCommon\tool_tracemem.h"
     489                                >
     490                        </File>
     491                        <File
    484492                                RelativePath="..\..\source\Lib\TLibCommon\TypeDef.h"
    485493                                >
    486494                        </File>
  • source/App/TAppCommon/program_options_lite.cpp

     
    1515Options::~Options()
    1616{
    1717        for(Options::NamesPtrList::iterator it = opt_list.begin(); it != opt_list.end(); it++) {
    18                 delete *it;
     18                MEMDELETE( *it );
    1919        }
    2020}
    2121
    2222void Options::addOption(OptionBase *opt)
    2323{
    24         Names* names = new Names();
     24        Names* names = MEMNEW Names();
    2525        names->opt = opt;
    2626        string& opt_string = opt->opt_string;
    2727
  • source/App/TAppCommon/program_options_lite.h

     
    44#include <list>
    55#include <map>
    66
     7#include "../../Lib/TLibCommon/tool_tracemem.h"
     8
    79namespace df {
    810namespace program_options_lite {
    911
     
    100102                Names() : opt(0) {};
    101103                ~Names() {
    102104                        if (opt)
    103                                 delete opt;
     105                                MEMDELETE( opt );
    104106                }
    105107                std::list<std::string> opt_long;
    106108                std::list<std::string> opt_short;
     
    132134        template<typename T>
    133135        OptionSpecific&
    134136        operator()(const std::string& name, T& storage, T default_val, const std::string& desc = "") {
    135                 parent.addOption(new Option<T>(name, storage, default_val, desc));
     137                parent.addOption(MEMNEW Option<T>(name, storage, default_val, desc));
    136138                return *this;
    137139        }
    138140
     
    145147         */
    146148        OptionSpecific&
    147149        operator()(const std::string& name, OptionFunc::Func *func, const std::string& desc = "") {
    148                 parent.addOption(new OptionFunc(name, parent, func, desc));
     150                parent.addOption(MEMNEW OptionFunc(name, parent, func, desc));
    149151                return *this;
    150152        }
    151153private:
  • source/App/TAppDecoder/decmain.cpp

     
    3737#include <time.h>
    3838#include "TAppDecTop.h"
    3939
     40#include <cassert>
     41#include "../../Lib/TLibCommon/tool_tracemem.h"
     42
    4043// ====================================================================================================================
    4144// Main function
    4245// ====================================================================================================================
    4346
    4447int main(int argc, char* argv[])
    4548{
    46   TAppDecTop  cTAppDecTop;
     49  TAppDecTop  * pTAppDecTop = MEMNEW TAppDecTop;
     50  assert( pTAppDecTop != NULL );
    4751
    4852  // print information
    4953  fprintf( stdout, "\n" );
     
    5458  fprintf( stdout, "\n" );
    5559
    5660  // create application decoder class
    57   cTAppDecTop.create();
     61  pTAppDecTop->create();
    5862
    5963  // parse configuration
    60   if(!cTAppDecTop.parseCfg( argc, argv ))
     64  if(!pTAppDecTop->parseCfg( argc, argv ))
    6165  {
    62     cTAppDecTop.destroy();
     66    pTAppDecTop->destroy();
    6367    return 1;
    6468  }
    6569
     
    6872  long lBefore = clock();
    6973
    7074  // call decoding function
    71   cTAppDecTop.decode();
     75  pTAppDecTop->decode();
    7276
    7377  // ending time
    7478  dResult = (double)(clock()-lBefore) / CLOCKS_PER_SEC;
    7579  printf("\n Total Time: %12.3f sec.\n", dResult);
    7680
    7781  // destroy application decoder class
    78   cTAppDecTop.destroy();
     82  pTAppDecTop->destroy();
     83  MEMDELETE( pTAppDecTop );
     84  pTAppDecTop = NULL;
    7985
     86  // memory log
     87  MEMTRACEINFO( stdout );
     88
    8089  return 0;
    8190}
    8291
  • source/App/TAppDecoder/TAppDecCfg.cpp

     
    3535
    3636#include "TAppDecCfg.h"
    3737
     38#include "../../Lib/TLibCommon/tool_tracemem.h"
     39
    3840// ====================================================================================================================
    3941// Public member functions
    4042// ====================================================================================================================
     
    6264  if( ! m_apcOpt->hasOptions() || !m_apcOpt->getValue( 'b' ) )
    6365  {
    6466    m_apcOpt->printUsage();
    65     delete m_apcOpt;
     67    MEMDELETE( m_apcOpt );
    6668    m_apcOpt = NULL;
    6769    return false;
    6870  }
  • source/App/TAppDecoder/TAppDecOption.cpp

     
    6666#include <cstring>
    6767#include "TAppDecOption.h"
    6868
     69#include "../../Lib/TLibCommon/tool_tracemem.h"
     70
    6971TAppOption::TAppOption()
    7072{
    7173  init();
     
    961963  length = int( is.tellg() );
    962964  is.seekg (0, ios::beg);
    963965//        buffer = (char*) malloc(length*sizeof(char));
    964   buffer = new char[length]; //kolya
     966  buffer = MEMNEWARRAY char[length]; //kolya
    965967  is.read (buffer, length);
    966968  is.close();
    967969  return buffer;
     
    10011003    cursor++; /* keep moving */
    10021004    linelength++;
    10031005  }
    1004   delete [] buffer; //kolya
     1006  MEMDELETEARRAY( buffer ); //kolya
    10051007  buffer = NULL;
    10061008  return true;
    10071009}
     
    10311033TAppOption::processLine( char *theline, int length  )
    10321034{
    10331035  bool found = false;
    1034   char *pline = new char[length+1];
     1036  char *pline = MEMNEWARRAY char[length+1];
    10351037  for( int i = 0 ; i < length ; i ++ )
    10361038    pline[i]= *(theline++);
    10371039  pline[length] = nullterminate;
     
    10551057    if( !found ) /* not a pair */
    10561058      justValue( pline );
    10571059  }
    1058   delete [] pline;
     1060  MEMDELETEARRAY( pline );
    10591061  pline = NULL;
    10601062}
    10611063
  • source/App/TAppDecoder/TAppDecTop.cpp

     
    6161
    6262Void TAppDecTop::create()
    6363{
    64   m_apcOpt        = new TAppOption();
    65   m_apcBitstream  = new TComBitstream;
     64  m_apcOpt        = MEMNEW TAppOption();
     65  m_apcBitstream  = MEMNEW TComBitstream;
    6666
    6767  m_apcBitstream->create( BITS_BUF_SIZE );
    6868}
     
    7171{
    7272  if ( m_apcOpt )
    7373  {
    74     delete m_apcOpt;
     74    MEMDELETE( m_apcOpt );
    7575    m_apcOpt = NULL;
    7676  }
    7777  if ( m_apcBitstream )
    7878  {
    7979    m_apcBitstream->destroy();
    80     delete m_apcBitstream;
     80    MEMDELETE( m_apcBitstream );
    8181    m_apcBitstream = NULL;
    8282  }
    8383}
  • source/App/TAppEncoder/encmain.cpp

     
    3636#include <time.h>
    3737#include "TAppEncTop.h"
    3838
     39#include <cassert>
     40#include "../../Lib/TLibCommon/tool_tracemem.h"
     41
    3942// ====================================================================================================================
    4043// Main function
    4144// ====================================================================================================================
    4245
    4346int main(int argc, char* argv[])
    4447{
    45   TAppEncTop  cTAppEncTop;
     48  TAppEncTop  * pTAppEncTop = MEMNEW TAppEncTop;
     49  assert( pTAppEncTop != NULL );
    4650
    4751  // print information
    4852  fprintf( stdout, "\n" );
     
    5357  fprintf( stdout, "\n" );
    5458
    5559  // create application encoder class
    56   cTAppEncTop.create();
     60  pTAppEncTop->create();
    5761
    5862  // parse configuration
    59   if(!cTAppEncTop.parseCfg( argc, argv ))
     63  if(!pTAppEncTop->parseCfg( argc, argv ))
    6064  {
    61     cTAppEncTop.destroy();
     65    pTAppEncTop->destroy();
    6266    return 1;
    6367  }
    6468
     
    6771  long lBefore = clock();
    6872
    6973  // call encoding function
    70   cTAppEncTop.encode();
     74  pTAppEncTop->encode();
    7175
    7276  // ending time
    7377  dResult = (double)(clock()-lBefore) / CLOCKS_PER_SEC;
    7478  printf("\n Total Time: %12.3f sec.\n", dResult);
    7579
    7680  // destroy application encoder class
    77   cTAppEncTop.destroy();
     81  pTAppEncTop->destroy();
     82  MEMDELETE( pTAppEncTop );
     83  pTAppEncTop = NULL;
    7884
     85  // memory log
     86  MEMTRACEINFO( stdout );
     87
    7988  return 0;
    8089}
    8190
  • source/App/TAppEncoder/TAppEncCfg.cpp

     
    4040#include "TAppEncCfg.h"
    4141#include "../../App/TAppCommon/program_options_lite.h"
    4242
     43#include "../../Lib/TLibCommon/tool_tracemem.h"
     44
    4345#ifdef WIN32
    4446#define strdup _strdup
    4547#endif
     
    7577{
    7678  if ( m_aidQP )
    7779  {
    78     delete[] m_aidQP;
     80    MEMDELETEARRAY( m_aidQP );
    7981  }
    8082}
    8183
     
    289291  m_iSourceHeight += m_aiPad[1];
    290292
    291293  // allocate slice-based dQP values
    292   m_aidQP = new Int[ m_iFrameToBeEncoded + m_iRateGOPSize + 1 ];
     294  m_aidQP = MEMNEWARRAY Int[ m_iFrameToBeEncoded + m_iRateGOPSize + 1 ];
    293295  ::memset( m_aidQP, 0, sizeof(Int)*( m_iFrameToBeEncoded + m_iRateGOPSize + 1 ) );
    294296
    295297  // handling of floating-point QP values
  • source/App/TAppEncoder/TAppEncTop.cpp

     
    199199 */
    200200Void TAppEncTop::encode()
    201201{
    202   TComPicYuv*       pcPicYuvOrg = new TComPicYuv;
     202  TComPicYuv*       pcPicYuvOrg = MEMNEW TComPicYuv;
    203203  TComPicYuv*       pcPicYuvRec = NULL;
    204204  TComBitstream*    pcBitstream = NULL;
    205205
     
    242242
    243243  // delete original YUV buffer
    244244  pcPicYuvOrg->destroy();
    245   delete pcPicYuvOrg;
     245  MEMDELETE( pcPicYuvOrg );
    246246  pcPicYuvOrg = NULL;
    247247
    248248  // delete used buffers in encoder class
     
    271271  {
    272272    if (m_cListPicYuvRec.size() == 0)
    273273    {
    274       rpcPicYuvRec = new TComPicYuv;
    275       rpcBitStream = new TComBitstream;
     274      rpcPicYuvRec = MEMNEW TComPicYuv;
     275      rpcBitStream = MEMNEW TComBitstream;
    276276
    277277      rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
    278278      rpcBitStream->create( (m_iSourceWidth * m_iSourceHeight * 3) >> 1 );
     
    300300  }
    301301  else
    302302  {
    303     rpcPicYuvRec = new TComPicYuv;
    304     rpcBitStream = new TComBitstream;
     303    rpcPicYuvRec = MEMNEW TComPicYuv;
     304    rpcBitStream = MEMNEW TComBitstream;
    305305
    306306    rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
    307307    rpcBitStream->create( (m_iSourceWidth * m_iSourceHeight * 3) >> 1 );
     
    325325    pcPicYuvRec->destroy();
    326326    pcBitstream->destroy();
    327327
    328     delete pcPicYuvRec; pcPicYuvRec = NULL;
    329     delete pcBitstream; pcBitstream = NULL;
     328    MEMDELETE( pcPicYuvRec ); pcPicYuvRec = NULL;
     329    MEMDELETE( pcBitstream ); pcBitstream = NULL;
    330330  }
    331331
    332332}
  • source/Lib/TLibCommon/CommonDef.h

     
    122122#define ClipMax(x)                  ( Min(g_uiBASE_MAX, x            ) )                              ///< clip with max. value
    123123#define Clip3( MinVal, MaxVal, a)   ( ((a)<(MinVal)) ? (MinVal) : (((a)>(MaxVal)) ? (MaxVal) :(a)) )  ///< general min/max clip
    124124
     125#ifdef CTRL_USE_TRACEMEM
     126#define xMalloc( type, len )        MEMNEWARRAY type[len]
     127#define xFree( ptr )                MEMDELETEARRAY( ptr )
     128#define calloc( num , size )            MEMNEW char[num*size]
     129#define free( ptr )                                     MEMDELETE( ptr )
     130#else
    125131#define DATA_ALIGN                  1                                                                 ///< use 32-bit aligned malloc/free
    126132#if     DATA_ALIGN && _WIN32 && ( _MSC_VER > 1300 )
    127133#define xMalloc( type, len )        _aligned_malloc( sizeof(type)*(len), 32 )
     
    130136#define xMalloc( type, len )        malloc   ( sizeof(type)*(len) )
    131137#define xFree( ptr )                free     ( ptr )
    132138#endif
     139#endif
    133140
    134141// ====================================================================================================================
    135142// Bug fixes
  • source/Lib/TLibCommon/ContextModel3DBuffer.cpp

     
    3535
    3636#include "ContextModel3DBuffer.h"
    3737
     38#include "tool_tracemem.h"
     39
    3840// ====================================================================================================================
    3941// Constructor / destructor / initialization / destroy
    4042// ====================================================================================================================
     
    4749
    4850{
    4951  // allocate 3D buffer
    50   m_pcContextModel = new ContextModel[ uiSizeZ * m_uiSizeY * m_uiSizeX ];
     52  m_pcContextModel = MEMNEWARRAY ContextModel[ uiSizeZ * m_uiSizeY * m_uiSizeX ];
    5153}
    5254
    5355ContextModel3DBuffer::~ContextModel3DBuffer()
    5456{
    5557  // delete 3D buffer
    56   delete [] m_pcContextModel;
     58  MEMDELETEARRAY( m_pcContextModel );
    5759  m_pcContextModel = NULL;
    5860}
    5961
  • source/Lib/TLibCommon/TComAdaptiveLoopFilter.cpp

     
    3939#include <stdio.h>
    4040#include <math.h>
    4141
     42#include "tool_tracemem.h"
     43
    4244#if HHI_ALF
    4345// ====================================================================================================================
    4446// Constructor / destructor / create / destroy
     
    5355{
    5456  if ( !m_pcTempPicYuv )
    5557  {
    56     m_pcTempPicYuv = new TComPicYuv;
     58    m_pcTempPicYuv = MEMNEW TComPicYuv;
    5759    m_pcTempPicYuv->create( iPicWidth, iPicHeight, uiMaxCUWidth, uiMaxCUHeight, uiMaxCUDepth );
    5860  }
    5961}
     
    6365  if ( m_pcTempPicYuv )
    6466  {
    6567    m_pcTempPicYuv->destroy();
    66     delete m_pcTempPicYuv;
     68    MEMDELETE( m_pcTempPicYuv );
    6769  }
    6870}
    6971
     
    8183  pAlfParam->pcQuadTree = NULL;
    8284  pAlfParam->bSeparateQt = false;
    8385
    84   pAlfParam->acHorizontalAlfFilter   = new AlfFilter[ ALF_FILT_FOR_CHROMA +1 ];
    85   pAlfParam->acVerticalAlfFilter     = new AlfFilter[ ALF_FILT_FOR_CHROMA +1 ];
     86  pAlfParam->acHorizontalAlfFilter   = MEMNEWARRAY AlfFilter[ ALF_FILT_FOR_CHROMA +1 ];
     87  pAlfParam->acVerticalAlfFilter     = MEMNEWARRAY AlfFilter[ ALF_FILT_FOR_CHROMA +1 ];
    8688
    8789  ::memset(pAlfParam->acHorizontalAlfFilter,  0, sizeof(AlfFilter)*( ALF_FILT_FOR_CHROMA +1 ) );
    8890  ::memset(pAlfParam->acVerticalAlfFilter  ,  0, sizeof(AlfFilter)*( ALF_FILT_FOR_CHROMA +1 ) );
     
    9092
    9193  pAlfParam->acHorizontalAlfFilter[ 0 ].bIsHorizontal         = true;
    9294  pAlfParam->acHorizontalAlfFilter[ 0 ].bIsVertical           = false;
    93   pAlfParam->acHorizontalAlfFilter[ 0 ].aiQuantFilterCoeffs   = new Int[ALF_MAX_NUM_COEF];
    94   pAlfParam->acHorizontalAlfFilter[ 0 ].aiTapCoeffMapping     = new Int[ALF_MAX_NUM_COEF];
    95   pAlfParam->acHorizontalAlfFilter[ 0 ].aiCoeffWeights        = new Int[ALF_MAX_NUM_COEF];
     95  pAlfParam->acHorizontalAlfFilter[ 0 ].aiQuantFilterCoeffs   = MEMNEWARRAY Int[ALF_MAX_NUM_COEF];
     96  pAlfParam->acHorizontalAlfFilter[ 0 ].aiTapCoeffMapping     = MEMNEWARRAY Int[ALF_MAX_NUM_COEF];
     97  pAlfParam->acHorizontalAlfFilter[ 0 ].aiCoeffWeights        = MEMNEWARRAY Int[ALF_MAX_NUM_COEF];
    9698  pAlfParam->acVerticalAlfFilter  [ 0 ].bIsHorizontal         = false;
    9799  pAlfParam->acVerticalAlfFilter  [ 0 ].bIsVertical           = true;
    98   pAlfParam->acVerticalAlfFilter  [ 0 ].aiQuantFilterCoeffs   = new Int[ALF_MAX_NUM_COEF];
    99   pAlfParam->acVerticalAlfFilter  [ 0 ].aiTapCoeffMapping     = new Int[ALF_MAX_NUM_COEF];
    100   pAlfParam->acVerticalAlfFilter  [ 0 ].aiCoeffWeights        = new Int[ALF_MAX_NUM_COEF];
     100  pAlfParam->acVerticalAlfFilter  [ 0 ].aiQuantFilterCoeffs   = MEMNEWARRAY Int[ALF_MAX_NUM_COEF];
     101  pAlfParam->acVerticalAlfFilter  [ 0 ].aiTapCoeffMapping     = MEMNEWARRAY Int[ALF_MAX_NUM_COEF];
     102  pAlfParam->acVerticalAlfFilter  [ 0 ].aiCoeffWeights        = MEMNEWARRAY Int[ALF_MAX_NUM_COEF];
    101103  ::memset( pAlfParam->acHorizontalAlfFilter[ 0 ].aiQuantFilterCoeffs , 0 , sizeof(Int) * ALF_MAX_NUM_COEF );
    102104  ::memset( pAlfParam->acHorizontalAlfFilter[ 0 ].aiTapCoeffMapping   , 0 , sizeof(Int) * ALF_MAX_NUM_COEF );
    103105  ::memset( pAlfParam->acHorizontalAlfFilter[ 0 ].aiCoeffWeights      , 0 , sizeof(Int) * ALF_MAX_NUM_COEF );
     
    109111  {
    110112    pAlfParam->acHorizontalAlfFilter[ uiIndx ].bIsHorizontal         = true;
    111113    pAlfParam->acHorizontalAlfFilter[ uiIndx ].bIsVertical           = false;
    112     pAlfParam->acHorizontalAlfFilter[ uiIndx ].aiQuantFilterCoeffs   = new Int[ALF_MAX_NUM_COEF];
     114    pAlfParam->acHorizontalAlfFilter[ uiIndx ].aiQuantFilterCoeffs   = MEMNEWARRAY Int[ALF_MAX_NUM_COEF];
    113115    pAlfParam->acVerticalAlfFilter  [ uiIndx ].bIsHorizontal         = false;
    114116    pAlfParam->acVerticalAlfFilter  [ uiIndx ].bIsVertical           = true;
    115     pAlfParam->acVerticalAlfFilter  [ uiIndx ].aiQuantFilterCoeffs   = new Int[ALF_MAX_NUM_COEF];
    116     pAlfParam->acVerticalAlfFilter  [ uiIndx ].aiTapCoeffMapping     = new Int[ALF_MAX_NUM_COEF];
    117     pAlfParam->acVerticalAlfFilter  [ uiIndx ].aiCoeffWeights        = new Int[ALF_MAX_NUM_COEF];
    118     pAlfParam->acHorizontalAlfFilter[ uiIndx ].aiTapCoeffMapping     = new Int[ALF_MAX_NUM_COEF];
    119     pAlfParam->acHorizontalAlfFilter[ uiIndx ].aiCoeffWeights        = new Int[ALF_MAX_NUM_COEF];
     117    pAlfParam->acVerticalAlfFilter  [ uiIndx ].aiQuantFilterCoeffs   = MEMNEWARRAY Int[ALF_MAX_NUM_COEF];
     118    pAlfParam->acVerticalAlfFilter  [ uiIndx ].aiTapCoeffMapping     = MEMNEWARRAY Int[ALF_MAX_NUM_COEF];
     119    pAlfParam->acVerticalAlfFilter  [ uiIndx ].aiCoeffWeights        = MEMNEWARRAY Int[ALF_MAX_NUM_COEF];
     120    pAlfParam->acHorizontalAlfFilter[ uiIndx ].aiTapCoeffMapping     = MEMNEWARRAY Int[ALF_MAX_NUM_COEF];
     121    pAlfParam->acHorizontalAlfFilter[ uiIndx ].aiCoeffWeights        = MEMNEWARRAY Int[ALF_MAX_NUM_COEF];
    120122    ::memset( pAlfParam->acHorizontalAlfFilter[ uiIndx ].aiQuantFilterCoeffs , 0 , sizeof(Int) * ALF_MAX_NUM_COEF );
    121123    ::memset( pAlfParam->acVerticalAlfFilter  [ uiIndx ].aiQuantFilterCoeffs , 0 , sizeof(Int) * ALF_MAX_NUM_COEF );
    122124    ::memset( pAlfParam->acHorizontalAlfFilter[ uiIndx ].aiTapCoeffMapping   , 0 , sizeof(Int) * ALF_MAX_NUM_COEF );
     
    138140    {
    139141      if( pAlfParam->acHorizontalAlfFilter[ uiIndx ].aiQuantFilterCoeffs != NULL )
    140142      {
    141         delete[] pAlfParam->acHorizontalAlfFilter[ uiIndx ].aiQuantFilterCoeffs;
     143        MEMDELETEARRAY( pAlfParam->acHorizontalAlfFilter[ uiIndx ].aiQuantFilterCoeffs );
    142144        pAlfParam->acHorizontalAlfFilter[ uiIndx ].aiQuantFilterCoeffs = NULL;
    143145      }
    144146      if( pAlfParam->acHorizontalAlfFilter[ uiIndx ].aiTapCoeffMapping != NULL )
    145147      {
    146         delete[] pAlfParam->acHorizontalAlfFilter[ uiIndx ].aiTapCoeffMapping;
     148        MEMDELETEARRAY( pAlfParam->acHorizontalAlfFilter[ uiIndx ].aiTapCoeffMapping );
    147149        pAlfParam->acHorizontalAlfFilter[ uiIndx ].aiTapCoeffMapping = NULL;
    148150      }
    149151      if( pAlfParam->acHorizontalAlfFilter[ uiIndx ].aiCoeffWeights != NULL )
    150152      {
    151         delete[] pAlfParam->acHorizontalAlfFilter[ uiIndx ].aiCoeffWeights;
     153        MEMDELETEARRAY( pAlfParam->acHorizontalAlfFilter[ uiIndx ].aiCoeffWeights );
    152154        pAlfParam->acHorizontalAlfFilter[ uiIndx ].aiCoeffWeights = NULL;
    153155      }
    154156    }
    155     delete[] pAlfParam->acHorizontalAlfFilter;
     157    MEMDELETEARRAY( pAlfParam->acHorizontalAlfFilter );
    156158    pAlfParam->acHorizontalAlfFilter = NULL;
    157159  }
    158160
     
    163165      {
    164166        if( pAlfParam->acVerticalAlfFilter[ uiIndx ].aiQuantFilterCoeffs != NULL )
    165167        {
    166           delete[] pAlfParam->acVerticalAlfFilter[ uiIndx ].aiQuantFilterCoeffs;
     168          MEMDELETEARRAY( pAlfParam->acVerticalAlfFilter[ uiIndx ].aiQuantFilterCoeffs );
    167169          pAlfParam->acVerticalAlfFilter[ uiIndx ].aiQuantFilterCoeffs = NULL;
    168170        }
    169171        if( pAlfParam->acVerticalAlfFilter[ uiIndx ].aiTapCoeffMapping != NULL )
    170172        {
    171           delete[] pAlfParam->acVerticalAlfFilter[ uiIndx ].aiTapCoeffMapping;
     173          MEMDELETEARRAY( pAlfParam->acVerticalAlfFilter[ uiIndx ].aiTapCoeffMapping );
    172174          pAlfParam->acVerticalAlfFilter[ uiIndx ].aiTapCoeffMapping = NULL;
    173175        }
    174176        if( pAlfParam->acVerticalAlfFilter[ uiIndx ].aiCoeffWeights != NULL )
    175177        {
    176           delete[] pAlfParam->acVerticalAlfFilter[ uiIndx ].aiCoeffWeights;
     178          MEMDELETEARRAY( pAlfParam->acVerticalAlfFilter[ uiIndx ].aiCoeffWeights );
    177179          pAlfParam->acVerticalAlfFilter[ uiIndx ].aiCoeffWeights = NULL;
    178180        }
    179181      }
    180       delete[] pAlfParam->acVerticalAlfFilter;
     182      MEMDELETEARRAY( pAlfParam->acVerticalAlfFilter );
    181183      pAlfParam->acVerticalAlfFilter = NULL;
    182184    }
    183185
     
    188190Void TComAdaptiveLoopFilter::destroyQuadTree(ALFParam* pcAlfParam)
    189191{
    190192  pcAlfParam->pcQuadTree->destroy();
    191   delete pcAlfParam->pcQuadTree;
     193  MEMDELETE( pcAlfParam->pcQuadTree );
    192194  pcAlfParam->pcQuadTree = NULL;
    193195}
    194196
     
    383385  if(pcAlfParam->cu_control_flag && iPlane ==0 )
    384386  {
    385387    // block-adaptive ALF process
    386     TComPicYuv* pcTempPicYuv2 = new TComPicYuv;
     388    TComPicYuv* pcTempPicYuv2 = MEMNEW TComPicYuv;
    387389    pcTempPicYuv2->create( pcPicRest->getWidth(), pcPicRest->getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
    388390    pcPicRest->copyToPicLuma( pcTempPicYuv2 );
    389391    xApplyFrame      ( pcPicRest, m_pcTempPicYuv , pcAlfParam->acVerticalAlfFilter  [0] );
     
    391393    //xCUAdaptive      ( m_pcAlfQuadTree, pcAlfParam->acHorizontalAlfFilter[0] , m_pcTempPicYuv, pcPicRest );
    392394    xCopyDecToRestCUs( pcAlfParam->pcQuadTree ,  pcTempPicYuv2 , pcPicRest );
    393395    pcTempPicYuv2->destroy();
    394     delete pcTempPicYuv2;
     396    MEMDELETE( pcTempPicYuv2 );
    395397  }
    396398  else
    397399  {
     
    12611263{
    12621264        if ( !m_pcTempPicYuv )
    12631265        {
    1264                 m_pcTempPicYuv = new TComPicYuv;
     1266                m_pcTempPicYuv = MEMNEW TComPicYuv;
    12651267                m_pcTempPicYuv->create( iPicWidth, iPicHeight, uiMaxCUWidth, uiMaxCUHeight, uiMaxCUDepth );
    12661268        }
    12671269#if QC_ALF
     
    12851287        if ( m_pcTempPicYuv )
    12861288        {
    12871289                m_pcTempPicYuv->destroy();
    1288                 delete m_pcTempPicYuv;
     1290                MEMDELETE( m_pcTempPicYuv );
    12891291        }
    12901292#if QC_ALF
    12911293        destroyMatrix_imgpel(imgY_var);
     
    13131315{
    13141316  pAlfParam->alf_flag = 0;
    13151317
    1316   pAlfParam->coeff                              = new Int[ALF_MAX_NUM_COEF];
    1317   pAlfParam->coeff_chroma = new Int[ALF_MAX_NUM_COEF_C];
     1318  pAlfParam->coeff                              = MEMNEWARRAY Int[ALF_MAX_NUM_COEF];
     1319  pAlfParam->coeff_chroma = MEMNEWARRAY Int[ALF_MAX_NUM_COEF_C];
    13181320
    13191321  ::memset(pAlfParam->coeff,                            0, sizeof(Int)*ALF_MAX_NUM_COEF         );
    13201322  ::memset(pAlfParam->coeff_chroma, 0, sizeof(Int)*ALF_MAX_NUM_COEF_C   );
    13211323#if QC_ALF
    1322   pAlfParam->coeffmulti = new Int*[NO_VAR_BINS];
     1324  pAlfParam->coeffmulti = MEMNEWARRAY Int*[NO_VAR_BINS];
    13231325  for (int i=0; i<NO_VAR_BINS; i++)
    13241326  {
    1325     pAlfParam->coeffmulti[i] = new Int[ALF_MAX_NUM_COEF];
     1327    pAlfParam->coeffmulti[i] = MEMNEWARRAY Int[ALF_MAX_NUM_COEF];
    13261328    ::memset(pAlfParam->coeffmulti[i],                          0, sizeof(Int)*ALF_MAX_NUM_COEF         );
    13271329  }
    13281330#endif
     
    13341336
    13351337  if (pAlfParam->coeff != NULL)
    13361338  {
    1337     delete[] pAlfParam->coeff;
     1339    MEMDELETEARRAY( pAlfParam->coeff );
    13381340    pAlfParam->coeff = NULL;
    13391341  }
    13401342
    13411343  if (pAlfParam->coeff_chroma != NULL)
    13421344  {
    1343     delete[] pAlfParam->coeff_chroma;
     1345    MEMDELETEARRAY( pAlfParam->coeff_chroma );
    13441346    pAlfParam->coeff_chroma = NULL;
    13451347  }
    13461348#if QC_ALF
    13471349  for (int i=0; i<NO_VAR_BINS; i++)
    13481350  {
    1349     delete[] pAlfParam->coeffmulti[i];
     1351    MEMDELETEARRAY( pAlfParam->coeffmulti[i] );
    13501352    pAlfParam->coeffmulti[i] = NULL;
    13511353  }
    1352   delete[] pAlfParam->coeffmulti;
     1354  MEMDELETEARRAY( pAlfParam->coeffmulti );
    13531355  pAlfParam->coeffmulti = NULL;
    13541356#endif
    13551357}
  • source/Lib/TLibCommon/TComBitBuffer.cpp

     
    3535
    3636#include "TComBitBuffer.h"
    3737
     38#include "tool_tracemem.h"
    3839
    3940TComBitBuffer::TComBitBuffer()
    40 : m_puiBuffer   ( new UInt [ STD_BIT_BUFFER_ALLOC_SIZE ] )
     41: m_puiBuffer   ( MEMNEWARRAY UInt [ STD_BIT_BUFFER_ALLOC_SIZE ] )
    4142, m_uiBufferSize( STD_BIT_BUFFER_ALLOC_SIZE )
    4243, m_uiWriteElemIdx  (  0 )
    4344, m_uiWriteAvailBits( 32 )
     
    4849
    4950TComBitBuffer::~TComBitBuffer()
    5051{
    51   delete [] m_puiBuffer;
     52  MEMDELETEARRAY( m_puiBuffer );
    5253}
    5354
    5455Void
    5556TComBitBuffer::xIncreaseBufferSize()
    5657{
    5758  UInt  uiNewBufferSize = ( m_uiBufferSize << 1 );
    58   UInt* puiNewBuffer    = new UInt [ uiNewBufferSize ];
     59  UInt* puiNewBuffer    = MEMNEWARRAY UInt [ uiNewBufferSize ];
    5960  ::memcpy( puiNewBuffer, m_puiBuffer, m_uiBufferSize * sizeof( UInt ) );
    60   delete [] m_puiBuffer;
     61  MEMDELETEARRAY( m_puiBuffer );
    6162  m_puiBuffer     = puiNewBuffer;
    6263  m_uiBufferSize  = uiNewBufferSize;
    6364}
  • source/Lib/TLibCommon/TComBitStream.cpp

     
    3636#include "TComBitStream.h"
    3737#include <memory.h>
    3838
     39#include "tool_tracemem.h"
     40
    3941// ====================================================================================================================
    4042// Constructor / destructor / create / destroy
    4143// ====================================================================================================================
     
    4446{
    4547  UInt uiSize = uiSizeInBytes / sizeof(UInt);
    4648 
    47   m_apulStreamPacketBegin = new UInt[uiSize];
     49  m_apulStreamPacketBegin = MEMNEWARRAY UInt[uiSize];
    4850  m_uiBufSize       = uiSize;
    4951  m_uiBitSize       = 0;
    5052  m_iValidBits      = 32;
     
    5759
    5860Void TComBitstream::destroy()
    5961{
    60   delete [] m_apulStreamPacketBegin;     m_apulStreamPacketBegin = NULL;
     62  MEMDELETEARRAY( m_apulStreamPacketBegin );     m_apulStreamPacketBegin = NULL;
    6163}
    6264
    6365// ====================================================================================================================
     
    313315  //make sure start pos is inside the buffer
    314316//  assert( uiStartPos > uiBytesInBuffer );
    315317 
    316   UChar* pucRead = new UChar[ uiBytesInBuffer ];
     318  UChar* pucRead = MEMNEWARRAY UChar[ uiBytesInBuffer ];
    317319  //th this is not nice but ...
    318320  memcpy( pucRead, getStartStream(), uiBytesInBuffer );
    319321
     
    340342    }
    341343  }
    342344
    343   delete [] pucRead;
     345  MEMDELETEARRAY( pucRead );
    344346  m_uiBitsWritten = uiWriteOffset << 3;
    345347}
    346348#endif
  • source/Lib/TLibCommon/TComLoopFilter.cpp

     
    3737#include "TComSlice.h"
    3838#include "TComMv.h"
    3939
     40#include "tool_tracemem.h"
     41
    4042// ====================================================================================================================
    4143// Constants
    4244// ====================================================================================================================
     
    112114  for( UInt uiDir = 0; uiDir < 2; uiDir++ )
    113115    for( UInt uiPlane = 0; uiPlane < 3; uiPlane++ )
    114116    {
    115       m_aapucBS       [uiDir][uiPlane] = new UChar[m_uiNumPartitions];
    116       m_aapbEdgeFilter[uiDir][uiPlane] = new Bool [m_uiNumPartitions];
     117      m_aapucBS       [uiDir][uiPlane] = MEMNEWARRAY UChar[m_uiNumPartitions];
     118      m_aapbEdgeFilter[uiDir][uiPlane] = MEMNEWARRAY Bool [m_uiNumPartitions];
    117119    }
    118120}
    119121
     
    122124  for( UInt uiDir = 0; uiDir < 2; uiDir++ )
    123125    for( UInt uiPlane = 0; uiPlane < 3; uiPlane++ )
    124126    {
    125       delete [] m_aapucBS       [uiDir][uiPlane];
    126       delete [] m_aapbEdgeFilter[uiDir][uiPlane];
     127      MEMDELETEARRAY( m_aapucBS       [uiDir][uiPlane] );
     128      MEMDELETEARRAY( m_aapbEdgeFilter[uiDir][uiPlane] );
    127129    }
    128130}
    129131#endif
  • source/Lib/TLibCommon/TComPic.cpp

     
    3535
    3636#include "TComPic.h"
    3737
     38#include "tool_tracemem.h"
     39
    3840// ====================================================================================================================
    3941// Constructor / destructor / create / destroy
    4042// ====================================================================================================================
     
    5961
    6062Void TComPic::create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Bool bIsVirtual )
    6163{
    62   m_apcPicSym     = new TComPicSym;  m_apcPicSym   ->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
     64  m_apcPicSym     = MEMNEW TComPicSym;  m_apcPicSym   ->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
    6365  if (!bIsVirtual)
    6466  {
    65     m_apcPicYuv[0]  = new TComPicYuv;  m_apcPicYuv[0]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
     67    m_apcPicYuv[0]  = MEMNEW TComPicYuv;  m_apcPicYuv[0]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
    6668  }
    67   m_apcPicYuv[1]  = new TComPicYuv;  m_apcPicYuv[1]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
     69  m_apcPicYuv[1]  = MEMNEW TComPicYuv;  m_apcPicYuv[1]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
    6870
    6971#if HHI_INTERP_FILTER
    7072  // buffer for filtered reconstructed pic
    71   m_apcPicYuv[2]  = new TComPicYuv;  m_apcPicYuv[2]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
     73  m_apcPicYuv[2]  = MEMNEW TComPicYuv;  m_apcPicYuv[2]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
    7274#endif
    7375
    7476  return;
     
    7981  if (m_apcPicSym)
    8082  {
    8183    m_apcPicSym->destroy();
    82     delete m_apcPicSym;
     84    MEMDELETE( m_apcPicSym );
    8385    m_apcPicSym = NULL;
    8486  }
    8587
    8688  if (m_apcPicYuv[0])
    8789  {
    8890    m_apcPicYuv[0]->destroy();
    89     delete m_apcPicYuv[0];
     91    MEMDELETE( m_apcPicYuv[0] );
    9092    m_apcPicYuv[0]  = NULL;
    9193  }
    9294
    9395  if (m_apcPicYuv[1])
    9496  {
    9597    m_apcPicYuv[1]->destroy();
    96     delete m_apcPicYuv[1];
     98    MEMDELETE( m_apcPicYuv[1] );
    9799    m_apcPicYuv[1]  = NULL;
    98100  }
    99101
     
    101103  if (m_apcPicYuv[2])
    102104  {
    103105    m_apcPicYuv[2]->destroy();
    104     delete m_apcPicYuv[2];
     106    MEMDELETE( m_apcPicYuv[2] );
    105107    m_apcPicYuv[2]  = NULL;
    106108  }
    107109#endif
  • source/Lib/TLibCommon/TComPicSym.cpp

     
    3535
    3636#include "TComPicSym.h"
    3737
     38#include "tool_tracemem.h"
     39
    3840// ====================================================================================================================
    3941// Constructor / destructor / create / destroy
    4042// ====================================================================================================================
     
    4345{
    4446  UInt i;
    4547
    46   m_apcTComSlice      = new TComSlice;
     48  m_apcTComSlice      = MEMNEW TComSlice;
    4749
    4850  m_uhTotalDepth      = uiMaxDepth;
    4951  m_uiNumPartitions   = 1<<(m_uhTotalDepth<<1);
     
    6163  m_uiHeightInCU      = ( iPicHeight%m_uiMaxCUHeight ) ? iPicHeight/m_uiMaxCUHeight + 1 : iPicHeight/m_uiMaxCUHeight;
    6264
    6365  m_uiNumCUsInFrame   = m_uiWidthInCU * m_uiHeightInCU;
    64   m_apcTComDataCU     = new TComDataCU*[m_uiNumCUsInFrame];
     66  m_apcTComDataCU     = MEMNEWARRAY TComDataCU*[m_uiNumCUsInFrame];
    6567
    6668  for ( i=0; i<m_uiNumCUsInFrame ; i++ )
    6769  {
    68     m_apcTComDataCU[i] = new TComDataCU;
     70    m_apcTComDataCU[i] = MEMNEW TComDataCU;
    6971    m_apcTComDataCU[i]->create( m_uiNumPartitions, m_uiMaxCUWidth, m_uiMaxCUHeight, false );
    7072  }
    7173}
     
    7476{
    7577  Int i;
    7678
    77   delete m_apcTComSlice;
     79  MEMDELETE( m_apcTComSlice );
    7880  m_apcTComSlice = NULL;
    7981
    8082
     
    8284  for (i = 0; i < m_uiNumCUsInFrame; i++)
    8385  {
    8486    m_apcTComDataCU[i]->destroy();
    85     delete m_apcTComDataCU[i];
     87    MEMDELETE( m_apcTComDataCU[i] );
    8688    m_apcTComDataCU[i] = NULL;
    8789  }
    88   delete [] m_apcTComDataCU;
     90  MEMDELETEARRAY( m_apcTComDataCU );
    8991  m_apcTComDataCU = NULL;
    9092}
    9193
  • source/Lib/TLibCommon/TComPredFilterMOMS.cpp

     
    3636
    3737#include "TComPredFilterMOMS.h"
    3838
     39#include "tool_tracemem.h"
     40
    3941#if HHI_INTERP_FILTER
    4042
    4143// predict luma block for a given motion vector for motion compensation
     
    346348Void TComPredFilter6TapMOMS::interpolate( Pel* pcDst, Int iDstStride, Pel* pcSrc, Int iSrcStride, Int iDstYMax, Int iDstXMax, Int iDx, Int iDy, Int iDstStep )
    347349{
    348350  // temp buffer
    349   Pel* pcTmpBufOrg         = new Pel[iDstXMax*(iDstYMax+5)];
     351  Pel* pcTmpBufOrg         = MEMNEWARRAY Pel[iDstXMax*(iDstYMax+5)];
    350352#if HHI_INTERP_FILTER_KERNEL_FIX
    351353  const Int iQ6Gain        = Int( pow((54.545454545454550),2) * pow(2.0,6) + 0.5 );
    352354#else
     
    431433    }
    432434  }
    433435
    434   delete[] pcTmpBufOrg;
     436  MEMDELETEARRAY( pcTmpBufOrg );
    435437}
    436438
    437439
     
    467469Void TComPredFilter4TapMOMS::interpolate( Pel* pcDst, Int iDstStride, Pel* pcSrc, Int iSrcStride, Int iDstYMax, Int iDstXMax, Int iDx, Int iDy, Int iDstStep )
    468470{
    469471  // temp buffer
    470   Pel* pcTmpBufOrg         = new Pel[iDstXMax*(iDstYMax+3)];
     472  Pel* pcTmpBufOrg         = MEMNEWARRAY Pel[iDstXMax*(iDstYMax+3)];
    471473
    472474  // interpolation in horizontal direction
    473475  {
     
    535537    }
    536538  }
    537539
    538   delete[] pcTmpBufOrg;
     540  MEMDELETEARRAY( pcTmpBufOrg );
    539541}
    540542
    541543
  • source/Lib/TLibCommon/TComPrediction.cpp

     
    3636#include <memory.h>
    3737#include "TComPrediction.h"
    3838
     39#include "tool_tracemem.h"
     40
    3941// ====================================================================================================================
    4042// Constructor / destructor / initialize
    4143// ====================================================================================================================
     
    5355{
    5456  m_cYuvExt.destroy();
    5557
    56   delete[] m_piYuvExt;
     58  MEMDELETEARRAY( m_piYuvExt );
    5759#ifdef EDGE_BASED_PREDICTION
    58   delete[] m_piYExtEdgeBased;
     60  MEMDELETEARRAY( m_piYExtEdgeBased );
    5961#endif //EDGE_BASED_PREDICTION
    6062
    6163  m_acYuvPred[0].destroy();
     
    6365
    6466  m_cYuvPredTemp.destroy();
    6567#ifdef EDGE_BASED_PREDICTION
    66   delete EdgeBasedPred;
     68  MEMDELETE( EdgeBasedPred );
    6769#endif //EDGE_BASED_PREDICTION
    6870
    6971}
     
    7678    m_iYuvExtStride = ((g_uiMaxCUWidth  + 12) << 4);
    7779
    7880    m_cYuvExt.create( m_iYuvExtStride, m_iYuvExtHeight );
    79     m_piYuvExt = new Int[ m_iYuvExtStride * m_iYuvExtHeight ];
     81    m_piYuvExt = MEMNEWARRAY Int[ m_iYuvExtStride * m_iYuvExtHeight ];
    8082
    8183    // new structure
    8284    m_acYuvPred[0] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
     
    9092  }
    9193#ifdef EDGE_BASED_PREDICTION
    9294  if( m_piYExtEdgeBased == NULL )
    93     m_piYExtEdgeBased = new Int[ ((g_uiMaxCUWidth<<1)+4) * ((g_uiMaxCUHeight<<1)+4) ];
     95    m_piYExtEdgeBased = MEMNEWARRAY Int[ ((g_uiMaxCUWidth<<1)+4) * ((g_uiMaxCUHeight<<1)+4) ];
    9496#endif //EDGE_BASED_PREDICTION
    9597
    9698  m_iDIFHalfTap   = ( m_iDIFTap  >> 1 );
    9799#ifdef EDGE_BASED_PREDICTION
    98   EdgeBasedPred = new TComEdgeBased;
     100  EdgeBasedPred = MEMNEW TComEdgeBased;
    99101#endif //EDGE_BASED_PREDICTION
    100102}
    101103
  • source/Lib/TLibCommon/TComRdCost.cpp

     
    3737#include <assert.h>
    3838#include "TComRdCost.h"
    3939
     40#include "tool_tracemem.h"
     41
    4042TComRdCost::TComRdCost()
    4143{
    4244  init();
     
    235237
    236238    m_iSearchLimit = iSubPelSearchLimit;
    237239
    238     m_puiComponentCostOriginP = new UInt[ 4 * iSubPelSearchLimit ];
     240    m_puiComponentCostOriginP = MEMNEWARRAY UInt[ 4 * iSubPelSearchLimit ];
    239241    iSubPelSearchLimit *= 2;
    240242
    241243    m_puiComponentCost = m_puiComponentCostOriginP + iSubPelSearchLimit;
     
    251253{
    252254  if( NULL != m_puiComponentCostOriginP )
    253255  {
    254     delete [] m_puiComponentCostOriginP;
     256    MEMDELETEARRAY( m_puiComponentCostOriginP );
    255257    m_puiComponentCostOriginP = NULL;
    256258  }
    257259}
  • source/Lib/TLibCommon/TComRom.cpp

     
    3737#include <memory.h>
    3838#include <stdlib.h>
    3939#include <stdio.h>
     40
     41#include "tool_tracemem.h"
     42
    4043// ====================================================================================================================
    4144// Initialize / destroy functions
    4245// ====================================================================================================================
     
    6467#endif
    6568  for ( i=0; i<MAX_CU_DEPTH; i++ )
    6669  {
    67     g_auiFrameScanXY[ i ] = new UInt[ c*c ];
    68     g_auiFrameScanX [ i ] = new UInt[ c*c ];
    69     g_auiFrameScanY [ i ] = new UInt[ c*c ];
     70    g_auiFrameScanXY[ i ] = MEMNEWARRAY UInt[ c*c ];
     71    g_auiFrameScanX [ i ] = MEMNEWARRAY UInt[ c*c ];
     72    g_auiFrameScanY [ i ] = MEMNEWARRAY UInt[ c*c ];
    7073    initFrameScanXY( g_auiFrameScanXY[i], g_auiFrameScanX[i], g_auiFrameScanY[i], c, c );
    7174    c <<= 1;
    7275  }
     
    7780  {
    7881    const int   iBlockSize    = 1 << i;
    7982    const UInt  uiNumScanPos  = UInt( iBlockSize * iBlockSize );
    80     g_auiSigLastScan[ i ][ 0 ] = new UInt[ uiNumScanPos ];
    81     g_auiSigLastScan[ i ][ 1 ] = new UInt[ uiNumScanPos ];
     83    g_auiSigLastScan[ i ][ 0 ] = MEMNEWARRAY UInt[ uiNumScanPos ];
     84    g_auiSigLastScan[ i ][ 1 ] = MEMNEWARRAY UInt[ uiNumScanPos ];
    8285    initSigLastScanPattern( g_auiSigLastScan[ i ][ 1 ], i, true  );
    8386    initSigLastScanPattern( g_auiSigLastScan[ i ][ 0 ], i, false );
    8487  }
     
    8891  int ipredmode;
    8992  for(ipredmode=0; ipredmode<9; ipredmode++)
    9093  {
    91     scanOrder4x4[ipredmode] = new UInt[ 4*4 ];
    92     scanOrder4x4X[ipredmode]= new UInt[ 4*4 ];
    93     scanOrder4x4Y[ipredmode]= new UInt[ 4*4 ];
     94    scanOrder4x4[ipredmode] = MEMNEWARRAY UInt[ 4*4 ];
     95    scanOrder4x4X[ipredmode]= MEMNEWARRAY UInt[ 4*4 ];
     96    scanOrder4x4Y[ipredmode]= MEMNEWARRAY UInt[ 4*4 ];
    9497   
    95     scanStats4x4[ipredmode] = new UInt[ 4*4 ];
     98    scanStats4x4[ipredmode] = MEMNEWARRAY UInt[ 4*4 ];
    9699   
    97100   
    98     scanOrder8x8[ipredmode] = new UInt[ 8*8 ];
    99     scanOrder8x8X[ipredmode]= new UInt[ 8*8 ];
    100     scanOrder8x8Y[ipredmode]= new UInt[ 8*8 ];
     101    scanOrder8x8[ipredmode] = MEMNEWARRAY UInt[ 8*8 ];
     102    scanOrder8x8X[ipredmode]= MEMNEWARRAY UInt[ 8*8 ];
     103    scanOrder8x8Y[ipredmode]= MEMNEWARRAY UInt[ 8*8 ];
    101104   
    102     scanStats8x8[ipredmode] = new UInt[ 8*8 ];
     105    scanStats8x8[ipredmode] = MEMNEWARRAY UInt[ 8*8 ];
    103106  }
    104107 
    105108  // 16x16
    106109  for (int z=0; z < NUM_SCANS_16x16; z++)
    107110  {
    108     scanOrder16x16[z] = new UInt[ 16*16 ];
    109     scanOrder16x16X[z] = new UInt[ 16*16 ];
    110     scanOrder16x16Y[z] = new UInt[ 16*16 ];
    111     scanStats16x16[z] = new UInt[ 16*16 ];
     111    scanOrder16x16[z] = MEMNEWARRAY UInt[ 16*16 ];
     112    scanOrder16x16X[z] = MEMNEWARRAY UInt[ 16*16 ];
     113    scanOrder16x16Y[z] = MEMNEWARRAY UInt[ 16*16 ];
     114    scanStats16x16[z] = MEMNEWARRAY UInt[ 16*16 ];
    112115  }
    113116 
    114117  // 32x32
    115118  for (int z=0; z < NUM_SCANS_32x32; z++)
    116119  {
    117     scanOrder32x32[z] = new UInt[ 32*32 ];
    118     scanOrder32x32X[z] = new UInt[ 32*32 ];
    119     scanOrder32x32Y[z] = new UInt[ 32*32 ];
    120     scanStats32x32[z] = new UInt[ 32*32 ];
     120    scanOrder32x32[z] = MEMNEWARRAY UInt[ 32*32 ];
     121    scanOrder32x32X[z] = MEMNEWARRAY UInt[ 32*32 ];
     122    scanOrder32x32Y[z] = MEMNEWARRAY UInt[ 32*32 ];
     123    scanStats32x32[z] = MEMNEWARRAY UInt[ 32*32 ];
    121124  }
    122125 
    123126  // 64x64
    124127  for (int z=0; z < NUM_SCANS_64x64; z++)
    125128  {
    126     scanOrder64x64[z] = new UInt[ 64*64 ];
    127     scanOrder64x64X[z] = new UInt[ 64*64 ];
    128     scanOrder64x64Y[z] = new UInt[ 64*64 ];
    129     scanStats64x64[z] = new UInt[ 64*64 ];
     129    scanOrder64x64[z] = MEMNEWARRAY UInt[ 64*64 ];
     130    scanOrder64x64X[z] = MEMNEWARRAY UInt[ 64*64 ];
     131    scanOrder64x64Y[z] = MEMNEWARRAY UInt[ 64*64 ];
     132    scanStats64x64[z] = MEMNEWARRAY UInt[ 64*64 ];
    130133  }
    131134#endif
    132135}
     
    137140
    138141  for ( i=0; i<MAX_CU_DEPTH; i++ )
    139142  {
    140     delete[] g_auiFrameScanXY[i];
    141     delete[] g_auiFrameScanX [i];
    142     delete[] g_auiFrameScanY [i];
     143    MEMDELETEARRAY( g_auiFrameScanXY[i] );
     144    MEMDELETEARRAY( g_auiFrameScanX [i] );
     145    MEMDELETEARRAY( g_auiFrameScanY [i] );
    143146  }
    144147 
    145148#if HHI_TRANSFORM_CODING
    146149  for ( i=0; i<MAX_CU_DEPTH+1; i++ )
    147150  {
    148     delete[] g_auiSigLastScan[i][0];
    149     delete[] g_auiSigLastScan[i][1];
     151    MEMDELETEARRAY( g_auiSigLastScan[i][0] );
     152    MEMDELETEARRAY( g_auiSigLastScan[i][1] );
    150153  }
    151154#endif
    152155
     
    154157  int ipredmode;
    155158  for(ipredmode=0; ipredmode<9; ipredmode++)
    156159  {       
    157     delete [] scanOrder4x4[ipredmode];     
    158     delete [] scanOrder4x4X[ipredmode];     
    159     delete [] scanOrder4x4Y[ipredmode];
    160     delete [] scanStats4x4[ipredmode];
     160    MEMDELETEARRAY( scanOrder4x4[ipredmode] );     
     161    MEMDELETEARRAY( scanOrder4x4X[ipredmode] );     
     162    MEMDELETEARRAY( scanOrder4x4Y[ipredmode] );
     163    MEMDELETEARRAY( scanStats4x4[ipredmode] );
    161164   
    162     delete [] scanOrder8x8[ipredmode];
    163     delete [] scanOrder8x8X[ipredmode];
    164     delete [] scanOrder8x8Y[ipredmode];
    165     delete [] scanStats8x8[ipredmode];
     165    MEMDELETEARRAY( scanOrder8x8[ipredmode] );
     166    MEMDELETEARRAY( scanOrder8x8X[ipredmode] );
     167    MEMDELETEARRAY( scanOrder8x8Y[ipredmode] );
     168    MEMDELETEARRAY( scanStats8x8[ipredmode] );
    166169  }
    167170 
    168171  // 16x16
    169172  for (int z=0; z < NUM_SCANS_16x16; z++)
    170173  {
    171     delete [] scanOrder16x16[z];
    172     delete [] scanOrder16x16X[z];
    173     delete [] scanOrder16x16Y[z];
    174     delete [] scanStats16x16[z];
     174    MEMDELETEARRAY( scanOrder16x16[z] );
     175    MEMDELETEARRAY( scanOrder16x16X[z] );
     176    MEMDELETEARRAY( scanOrder16x16Y[z] );
     177    MEMDELETEARRAY( scanStats16x16[z] );
    175178  }
    176179  // 32x32
    177180  for (int z=0; z < NUM_SCANS_32x32; z++)
    178181  {
    179     delete [] scanOrder32x32[z];
    180     delete [] scanOrder32x32X[z];
    181     delete [] scanOrder32x32Y[z];
    182     delete [] scanStats32x32[z];
     182    MEMDELETEARRAY( scanOrder32x32[z] );
     183    MEMDELETEARRAY( scanOrder32x32X[z] );
     184    MEMDELETEARRAY( scanOrder32x32Y[z] );
     185    MEMDELETEARRAY( scanStats32x32[z] );
    183186  }
    184187  // 64x64
    185188  for (int z=0; z < NUM_SCANS_64x64; z++)
    186189  {
    187     delete [] scanOrder64x64[z];
    188     delete [] scanOrder64x64X[z];
    189     delete [] scanOrder64x64Y[z];
    190     delete [] scanStats64x64[z];
     190    MEMDELETEARRAY( scanOrder64x64[z] );
     191    MEMDELETEARRAY( scanOrder64x64X[z] );
     192    MEMDELETEARRAY( scanOrder64x64Y[z] );
     193    MEMDELETEARRAY( scanStats64x64[z] );
    191194  }
    192195#endif
    193196}
  • source/Lib/TLibCommon/TComTrQuant.cpp

     
    4242#endif
    4343#include "ContextTables.h"
    4444
     45#include "tool_tracemem.h"
     46
    4547// ====================================================================================================================
    4648// Constants
    4749// ====================================================================================================================
     
    243245  m_cQP.clear();
    244246
    245247  // allocate temporary buffers
    246   m_plTempCoeff  = new Long[ MAX_CU_SIZE*MAX_CU_SIZE ];
     248  m_plTempCoeff  = MEMNEWARRAY Long[ MAX_CU_SIZE*MAX_CU_SIZE ];
    247249
    248250  // allocate bit estimation class  (for RDOQ)
    249   m_pcEstBitsSbac = new estBitsSbacStruct;
     251  m_pcEstBitsSbac = MEMNEW estBitsSbacStruct;
    250252}
    251253
    252254TComTrQuant::~TComTrQuant()
     
    254256  // delete temporary buffers
    255257  if ( m_plTempCoeff )
    256258  {
    257     delete [] m_plTempCoeff;
     259    MEMDELETEARRAY( m_plTempCoeff );
    258260    m_plTempCoeff = NULL;
    259261  }
    260262
    261263  // delete bit estimation class
    262   if ( m_pcEstBitsSbac ) delete m_pcEstBitsSbac;
     264  if ( m_pcEstBitsSbac ) MEMDELETE( m_pcEstBitsSbac );
    263265}
    264266
    265267/// Including Chroma QP Parameter setting
     
    68056807  UInt puiCtxCoeffLevelM1[MAX_CU_SIZE * MAX_CU_SIZE];
    68066808  UInt puiBaseCtx[MAX_CU_SIZE * MAX_CU_SIZE / 16];
    68076809 
    6808 //  Int*  piCoeff            = new Int [ uiMaxNumCoeff      ];
     6810//  Int*  piCoeff            = MEMNEWARRAY Int [ uiMaxNumCoeff      ];
    68096811//#if QC_MDDT
    6810 //  Int64* plLevelDouble     = new Int64[ uiMaxNumCoeff      ];
     6812//  Int64* plLevelDouble     = MEMNEWARRAY Int64[ uiMaxNumCoeff      ];
    68116813//#else
    6812 //  Long* plLevelDouble      = new Long[ uiMaxNumCoeff      ];
     6814//  Long* plLevelDouble      = MEMNEWARRAY Long[ uiMaxNumCoeff      ];
    68136815//#endif
    6814 //  UInt* puiCtxAbsGreOne    = new UInt[ uiMaxNumCoeff      ];
    6815 //  UInt* puiCtxCoeffLevelM1 = new UInt[ uiMaxNumCoeff      ];
    6816 //  UInt* puiBaseCtx         = new UInt[ uiMaxNumCoeff / 16 ];
     6816//  UInt* puiCtxAbsGreOne    = MEMNEWARRAY UInt[ uiMaxNumCoeff      ];
     6817//  UInt* puiCtxCoeffLevelM1 = MEMNEWARRAY UInt[ uiMaxNumCoeff      ];
     6818//  UInt* puiBaseCtx         = MEMNEWARRAY UInt[ uiMaxNumCoeff / 16 ];
    68176819  const UInt uiNumOfSets   = 4;
    68186820  const UInt uiNum4x4Blk   = max<UInt>( 1, uiMaxNumCoeff / 16 );
    68196821
     
    72547256    }
    72557257  }
    72567258
    7257 //  delete[] piCoeff;
    7258 //  delete[] plLevelDouble;
    7259 //  delete[] puiCtxAbsGreOne;
    7260 //  delete[] puiCtxCoeffLevelM1;
    7261 //  delete[] puiBaseCtx;
     7259//  MEMDELETEARRAY( piCoeff );
     7260//  MEMDELETEARRAY( plLevelDouble );
     7261//  MEMDELETEARRAY( puiCtxAbsGreOne );
     7262//  MEMDELETEARRAY( puiCtxCoeffLevelM1 );
     7263//  MEMDELETEARRAY( puiBaseCtx );
    72627264#else
    72637265// temporal buffer for speed
    72647266static levelDataStruct slevelData               [ MAX_CU_SIZE*MAX_CU_SIZE ];
  • source/Lib/TLibCommon/tool_tracemem.cpp

     
     1/****************************************************************************
     2                          tool_tracemem.cpp
     3                          -------------------
     4    begin                : Fri Oct 06 2006
     5    authors              : Xiang Li
     6        email                : xiangli@ieee.org
     7****************************************************************************/
     8
     9/****************************************************************************
     10    Implementation of tools for tracing memory allocation.
     11****************************************************************************/
     12
     13#include <stdio.h>
     14#include <assert.h>
     15#include "tool_tracemem.h"
     16
     17#ifdef CTRL_USE_TRACEMEM
     18
     19/***************************************************************************/
     20namespace Utilities
     21{
     22
     23#define TRACEMEM_REPORT_MISMATCH_NEWDEL         0
     24#define TRACEMEM_THRESHOLD_FILE_TIMESNEW        10000
     25#define TRACEMEM_THRESHOLD_FILE_BYTESALLOC      3000000
     26#define TRACEMEM_THRESHOLD_FILE_PER                     0.25
     27
     28CMemoryTrace::CMemoryTrace()
     29{
     30        m_szMaxRecord = 0;
     31        m_szCurUsed = 0;
     32        m_szMaxUsed = 0;
     33        m_uTimesNew = 0;
     34        m_uTimesDelMissed = 0;
     35}
     36
     37CMemoryTrace::~CMemoryTrace()
     38{
     39
     40}
     41
     42void CMemoryTrace::AddRecord( void * pMemory , size_t sz , char * pFileName , int nLine , bool bArray )
     43{
     44        if( pMemory != NULL )
     45        {
     46                assert( m_MemoryNew.find( ( size_t )pMemory ) == m_MemoryNew.end() );
     47               
     48                // record memory allocation
     49                xxGetFileName( pFileName , m_MemoryNew[ ( size_t )pMemory ].strFileNameNew );
     50                m_MemoryNew[ ( size_t )pMemory ].nLineNew = nLine;
     51                m_MemoryNew[ ( size_t )pMemory ].bArray = bArray;
     52                m_MemoryNew[ ( size_t )pMemory ].szSize = sz;
     53                m_szCurUsed += sz;
     54                if( m_szCurUsed > m_szMaxUsed )
     55                        m_szMaxUsed = m_szCurUsed;
     56                m_uTimesNew++;
     57
     58                // record the allocation from a file
     59                const std::string & rStr = m_MemoryNew[ ( size_t )pMemory ].strFileNameNew;
     60                if( m_MemoryFileNew.find( rStr ) == m_MemoryFileNew.end() )
     61                {
     62                        // new file
     63                        m_MemoryFileNew[ rStr ].strFileNameNew = rStr;
     64                        m_MemoryFileNew[ rStr ].szCurAllocated = sz;
     65                        m_MemoryFileNew[ rStr ].uTimesNew = 1;
     66                        m_MemoryFileNew[ rStr ].szMaxAllocated = sz;
     67                }
     68                else
     69                {
     70                        m_MemoryFileNew[ rStr ].szCurAllocated += sz;
     71                        m_MemoryFileNew[ rStr ].uTimesNew += 1;
     72                        if( m_MemoryFileNew[ rStr ].szMaxAllocated < m_MemoryFileNew[ rStr ].szCurAllocated )
     73                                m_MemoryFileNew[ rStr ].szMaxAllocated = m_MemoryFileNew[ rStr ].szCurAllocated;
     74                }
     75
     76                // max number of the records
     77                if( m_MemoryNew.size() > m_szMaxRecord )
     78                {
     79                        m_szMaxRecord = m_MemoryNew.size();
     80                }
     81
     82        }
     83}
     84
     85void CMemoryTrace::DelRecord( void * pMemory , char * pFileName , int nLine , bool bArray )
     86{
     87        if( pMemory != NULL )
     88        {
     89                if( m_MemoryNew.empty() == false && m_MemoryNew.find( ( size_t )pMemory ) != m_MemoryNew.end() )
     90                {
     91
     92#if TRACEMEM_REPORT_MISMATCH_NEWDEL
     93                        if( m_MemoryNew[ ( size_t )pMemory ].bArray != bArray )
     94                        {
     95                                // record the item which not paired properly
     96                                m_NotPairedNew[ ( size_t )pMemory ] = m_MemoryNew[ ( size_t )pMemory ];
     97                                xxGetFileName( pFileName , m_NotPairedNew[ ( size_t )pMemory ].strFileNameDel );
     98                                m_NotPairedNew[ ( size_t )pMemory ].nLineDel = nLine;
     99                        }
     100#endif
     101
     102                        // file record
     103                        const std::string & rStr = m_MemoryNew[ ( size_t )pMemory ].strFileNameNew;
     104                        m_MemoryFileNew[ rStr ].szCurAllocated -= m_MemoryNew[ ( size_t )pMemory ].szSize;
     105
     106                        // global record
     107                        m_szCurUsed = m_szCurUsed - m_MemoryNew[ ( size_t )pMemory ].szSize;
     108                        m_MemoryNew.erase( ( size_t )pMemory );
     109                }
     110                else
     111                {
     112                        xxGetFileName( pFileName , m_MemoryDel[ ( size_t )pMemory ].strFileNameDel );
     113                        m_MemoryDel[ ( size_t )pMemory ].nLineDel = nLine;
     114                        m_MemoryDel[ ( size_t )pMemory ].bArray = bArray;
     115                        m_uTimesDelMissed++;
     116                }
     117        }
     118}
     119
     120bool CMemoryTrace::HasBeenAllocated( void * pMemory )
     121{
     122        if( pMemory != NULL && m_MemoryNew.empty() == false )
     123                return( m_MemoryNew.find( ( size_t )pMemory ) != m_MemoryNew.end() );
     124        else
     125                return( false );
     126}
     127
     128void CMemoryTrace::OutputMemTraceInfo( FILE * fpLog )
     129{
     130        if( fpLog != NULL )
     131        {
     132                fprintf( fpLog , "\n\n******************** Memory Log ********************" );
     133
     134                char strMaxMemory[256] , strCurMemory[256];
     135
     136                if( m_szMaxUsed < 1000 )
     137                        sprintf( strMaxMemory , "%d B" , m_szMaxUsed );
     138                else if( m_szMaxUsed < 1000000 )
     139                        sprintf( strMaxMemory , "%.1lf KB" , m_szMaxUsed / 1000.0 );
     140                else
     141                        sprintf( strMaxMemory , "%.2lf MB" , m_szMaxUsed / 1000000.0 );
     142
     143                if( m_szCurUsed < 1000 )
     144                        sprintf( strCurMemory , "%d B" , m_szCurUsed );
     145                else if( m_szCurUsed < 1000000 )
     146                        sprintf( strCurMemory , "%.1lf KB" , m_szCurUsed / 1000.0 );
     147                else
     148                        sprintf( strCurMemory , "%.2lf MB" , m_szCurUsed / 1000000.0 );
     149
     150                fprintf( fpLog , "\nAllocating memory %lld times, incorrect deleting %lld times." , m_uTimesNew , m_uTimesDelMissed );
     151                fprintf( fpLog , "\nMax %s were allocated, %s have not be freed." , strMaxMemory , strCurMemory );
     152                fprintf( fpLog , "\nMax %d records." , m_szMaxRecord );
     153
     154                if( m_MemoryNew.empty() == false )
     155                {
     156                        fprintf( fpLog , "\n----------------------------------------------------" );
     157                        fprintf( fpLog , "\nMemory has not been freed:" );
     158                        HASH_MAP < unsigned int , SMemoryRecord >::iterator CurPos = m_MemoryNew.begin();
     159                        while( CurPos != m_MemoryNew.end() )
     160                        {
     161                                fprintf( fpLog , "\nIn %s line %d, memory was allocated at 0x%08x (%dB)." , CurPos->second.strFileNameNew.c_str() ,
     162                                        CurPos->second.nLineNew , CurPos->first , CurPos->second.szSize );
     163                                CurPos++;
     164                        }
     165                }
     166
     167                if( m_MemoryDel.empty() == false )
     168                {
     169                        fprintf( fpLog , "\n----------------------------------------------------" );
     170                        fprintf( fpLog , "\nIncorrect delete:" );
     171                        HASH_MAP < unsigned int , SMemoryRecord >::iterator CurPos = m_MemoryDel.begin();
     172                        while( CurPos != m_MemoryDel.end() )
     173                        {
     174                                fprintf( fpLog , "\nIn %s line %d, memory 0x%08x was incorrectly deleted." , CurPos->second.strFileNameDel.c_str() ,
     175                                        CurPos->second.nLineDel , CurPos->first );
     176                                CurPos++;
     177                        }
     178                }
     179
     180#if TRACEMEM_REPORT_MISMATCH_NEWDEL
     181                if( m_NotPairedNew.empty() == false )
     182                {
     183                        fprintf( fpLog , "\n----------------------------------------------------" );
     184                        fprintf( fpLog , "\nnew/new[] not paired by proper delete/delete[]:" );
     185                        HASH_MAP < unsigned int , SMemoryRecord >::iterator CurPos = m_NotPairedNew.begin();
     186                        while( CurPos != m_NotPairedNew.end() )
     187                        {
     188                                fprintf( fpLog , "\nIn %s line %d, new 0x%08x was by allocated by %s while freed by %s in %s line %d." ,
     189                                        CurPos->second.strFileNameNew.c_str() , CurPos->second.nLineNew , CurPos->first ,
     190                                        CurPos->second.bArray == false ? "MEMNEW" : "MEMNEWARRAY" ,
     191                                        CurPos->second.bArray == true ? "MEMDELETE" : "DELETEARRAY" ,
     192                                        CurPos->second.strFileNameDel.c_str() , CurPos->second.nLineDel );
     193                                CurPos++;
     194                        }
     195                }
     196#endif
     197
     198                if( m_MemoryFileNew.empty() == false )
     199                {
     200                        fprintf( fpLog , "\n----------------------------------------------------" );
     201                        fprintf( fpLog , "\nFiles of frequent memory allocation and files using much memory:" );
     202                        std::map < std::string , SFileMemory >::iterator CurPos = m_MemoryFileNew.begin();
     203                        while( CurPos != m_MemoryFileNew.end() )
     204                        {
     205                                if( CurPos->second.uTimesNew >= TRACEMEM_THRESHOLD_FILE_TIMESNEW
     206                                        || CurPos->second.uTimesNew >= TRACEMEM_THRESHOLD_FILE_PER * m_uTimesNew
     207                                        || CurPos->second.szMaxAllocated >= TRACEMEM_THRESHOLD_FILE_BYTESALLOC
     208                                        || CurPos->second.szMaxAllocated >= TRACEMEM_THRESHOLD_FILE_PER * m_szMaxUsed )
     209                                {
     210                                        const size_t & rMaxUsed = CurPos->second.szMaxAllocated;
     211                                        if( rMaxUsed < 1000 )
     212                                                sprintf( strMaxMemory , "%d B" , rMaxUsed );
     213                                        else if( rMaxUsed < 1000000 )
     214                                                sprintf( strMaxMemory , "%.1lf KB" , rMaxUsed / 1000.0 );
     215                                        else
     216                                                sprintf( strMaxMemory , "%.2lf MB" , rMaxUsed / 1000000.0 );
     217                                        fprintf( fpLog , "\n%s, %lld times (%.2lf%%) allocation, max %s were allocated." , CurPos->second.strFileNameNew.c_str() ,
     218                                                CurPos->second.uTimesNew , CurPos->second.uTimesNew * 100.0 / m_uTimesNew , strMaxMemory );
     219                                }
     220                                CurPos++;
     221                        }
     222                }
     223
     224                fprintf( fpLog , "\n****************************************************\n" );
     225        }
     226
     227        xxRelease();
     228}
     229
     230void CMemoryTrace::xxGetFileName( const char * pPathFileName , std::string & rFileName ) const
     231{
     232        rFileName = pPathFileName;
     233        size_t nLast = rFileName.find_last_of( CSLASH );
     234        if( nLast + 1 < std::string::npos )
     235                rFileName.erase( 0 , nLast + 1 );
     236}
     237
     238void CMemoryTrace::xxRelease()
     239{
     240        m_MemoryNew.clear();
     241        m_MemoryDel.clear();
     242        m_NotPairedNew.clear();
     243}
     244
     245} // namespace Utilities
     246/***************************************************************************/
     247
     248/** global variables *******************************************************/
     249Utilities::CMemoryTrace gMemoryTrace;
     250/***************************************************************************/
     251
     252/** new and delete *********************************************************/
     253void * operator new( size_t sz , char * pFileName , int nLine , bool bArray )
     254{
     255        void * pMemory = operator new( sz );
     256
     257        gMemoryTrace.AddRecord( pMemory , sz , pFileName , nLine , bArray );
     258
     259        return( pMemory );
     260}
     261
     262void * operator new[] ( size_t sz , char * pFileName , int nLine , bool bArray )
     263{
     264        void * pMemory = operator new( sz );
     265
     266        gMemoryTrace.AddRecord( pMemory , sz , pFileName , nLine , bArray );
     267
     268        return( pMemory );
     269}
     270
     271void operator delete( void * pMemory , char * pFileName , int nLine , bool bArray )
     272{
     273        if( pMemory != NULL )
     274        {
     275                gMemoryTrace.DelRecord( pMemory , pFileName , nLine , bArray );
     276                operator delete ( pMemory );
     277        }
     278}
     279
     280void operator delete [] ( void * pMemory , char * pFileName , int nLine , bool bArray )
     281{
     282        if( pMemory != NULL )
     283        {
     284                gMemoryTrace.DelRecord( pMemory , pFileName , nLine , bArray );
     285                operator delete ( pMemory );
     286        }
     287}
     288
     289void OutputMemTraceInfo(  FILE * fpLog )
     290{
     291        gMemoryTrace.OutputMemTraceInfo( fpLog );
     292}
     293
     294
     295/***************************************************************************/
     296
     297#endif // CTRL_USE_TRACEMEM
     298
     299double GetMaxMBMemAllocated()
     300{
     301        double dReturn = 0;
     302
     303#ifdef CTRL_USE_TRACEMEM
     304        dReturn = gMemoryTrace.GetMaxMBMemAllocated();
     305#endif
     306
     307        return( dReturn );
     308}
     309
     310double GetTimesMemAllocation()
     311{
     312        double dReturn = 0;
     313
     314#ifdef CTRL_USE_TRACEMEM
     315        dReturn = gMemoryTrace.GetTimesMemAllocation();
     316#endif
     317
     318        return( dReturn );
     319}
     320
     321/****************************************************************************
     322    end-of-file
     323****************************************************************************/
  • source/Lib/TLibCommon/tool_tracemem.h

     
     1/****************************************************************************
     2                          tool_tracemem.h
     3                          -------------------
     4    begin                : Fri Oct 06 2006
     5    authors              : Xiang Li
     6    email                : xiangli@ieee.org
     7****************************************************************************/
     8
     9#ifndef __TOOL_TRACEMEM_H__
     10#define __TOOL_TRACEMEM_H__
     11
     12/****************************************************************************
     13    Implementations of tools for tracing memory allocation.
     14****************************************************************************/
     15
     16/** standard headers *******************************************************/
     17#include <string>
     18#include <map>
     19#ifdef WIN32
     20        #include <hash_map>
     21#else
     22        #include <ext/hash_map>
     23#endif
     24/***************************************************************************/
     25
     26/** control definition *****************************************************/
     27#define CTRL_USE_TRACEMEM
     28/***************************************************************************/
     29
     30#ifdef CTRL_USE_TRACEMEM
     31
     32/***************************************************************************/
     33namespace Utilities
     34{
     35
     36#ifdef WIN32
     37        #define HASH_MAP stdext::hash_map
     38        #define CSLASH   '\\'
     39        typedef unsigned __int64 uint64_t;
     40#else
     41        #define HASH_MAP __gnu_cxx::hash_map
     42        #define CSLASH   '/'
     43        typedef unsigned long long uint64_t;
     44#endif
     45
     46//! class for memory tracing
     47class CMemoryTrace
     48{
     49
     50public:
     51
     52/** function members *******************************************************/
     53
     54        //! constructor
     55        CMemoryTrace();
     56
     57        //! destructor
     58        ~CMemoryTrace();
     59
     60        /***********************************************************************/
     61          /*!
     62           * \short add a record for the operator new
     63           *
     64           * \param pMemory, pointer to the memory just newed
     65           * \param sz, size of memory to be newed
     66           * \param pFileName, indicates the file which calls new
     67           * \param nLine, indicates the line where new is called
     68           * \param bArray, whether by new []
     69           */
     70        /***********************************************************************/
     71        void AddRecord( void * pMemory , size_t sz , char * pFileName , int nLine , bool bArray );
     72
     73        /***********************************************************************/
     74          /*!
     75           * \short add a record for the operator delete
     76           *
     77           * \param pMemory, pointer to the memory to be deleted
     78           * \param pFileName, indicates the file which calls new
     79           * \param nLine, indicates the line where new is called
     80           * \param bArray, whether by delete []
     81           */
     82        /***********************************************************************/
     83        void DelRecord( void * pMemory , char * pFileName , int nLine , bool bArray );
     84
     85        /***********************************************************************/
     86          /*!
     87           * \short check whether the memory has been recorded for the operator new
     88           *
     89           * \param pMemory, pointer to the memory
     90           */
     91        /***********************************************************************/
     92        bool HasBeenAllocated( void * pMemory );
     93
     94        /***********************************************************************/
     95          /*!
     96           * \short output the memory tracing information
     97           */
     98        /***********************************************************************/
     99        void OutputMemTraceInfo( FILE * fpLog );
     100
     101        /***********************************************************************/
     102          /*!
     103           * \short Get the memory (in MBytes) has been allocated
     104           *
     105           * \return memory has been allocated
     106           */
     107        /***********************************************************************/
     108        double GetMaxMBMemAllocated()
     109        {
     110                return( m_szMaxUsed / 1000000.0 );
     111        }
     112
     113        /***********************************************************************/
     114          /*!
     115           * \short Get the times of memory allocation
     116           *
     117           * \return the times of memory allocation
     118           */
     119        /***********************************************************************/
     120        double GetTimesMemAllocation()
     121        {
     122                return( ( double )( m_uTimesNew ) );
     123        }
     124
     125/***************************************************************************/
     126
     127private:
     128
     129/** private structure ******************************************************/
     130
     131        //! record of memory tracing
     132        typedef struct _SMemoryRecord
     133        {
     134                //! indicates the file which calls new
     135                std::string strFileNameNew;
     136
     137                //! indicates the line where new is called
     138                int nLineNew;
     139
     140                //! the size to be newed
     141                size_t szSize;
     142
     143                //! whether allocated by new []
     144                bool bArray;
     145
     146                //! indicates the file which calls delete
     147                std::string strFileNameDel;
     148
     149                //! indicates the line where delete is called
     150                int nLineDel;
     151
     152        }SMemoryRecord;
     153
     154        //! statistics of memory allocation from a file
     155        typedef struct _SFileMemory
     156        {
     157                //! indicates the file which calls new
     158                std::string strFileNameNew;
     159
     160                //! max bytes have been allocated from the file
     161                size_t  szMaxAllocated;
     162
     163                //! current bytes have been allocated from the file
     164                size_t  szCurAllocated;
     165
     166                //! number of allocation from the file
     167                uint64_t uTimesNew;
     168
     169        }SFileMemory;
     170
     171/***************************************************************************/
     172
     173/** variable members *******************************************************/
     174
     175        //! max bytes have been allocated
     176        size_t  m_szMaxUsed;
     177
     178        //! current bytes have been allocated
     179        size_t  m_szCurUsed;
     180
     181        //! the times the operator new has been called
     182        uint64_t m_uTimesNew;
     183
     184        //! the times the operator delete has missed (the memory to be deleted was not recorded)
     185        uint64_t m_uTimesDelMissed;
     186
     187        //! max number of elements in m_uTimesNew
     188        size_t m_szMaxRecord;
     189
     190        //! records of new
     191        HASH_MAP < size_t , SMemoryRecord > m_MemoryNew;
     192
     193        //! records of delete
     194        HASH_MAP < size_t , SMemoryRecord > m_MemoryDel;
     195
     196        //! records of new/new[] not paired by proper delete/delete[]
     197        HASH_MAP < size_t , SMemoryRecord > m_NotPairedNew;
     198
     199        //! records of new from a file
     200        std::map < std::string , SFileMemory > m_MemoryFileNew;
     201
     202/***************************************************************************/
     203
     204/** function members *******************************************************/
     205
     206        /***********************************************************************/
     207          /*!
     208           * \short Get file name (remove the path info)
     209           *
     210           * \param pPathFileName, pointer to the file name with path info
     211           * \param rFileName, reference to get the file name
     212           */
     213        /***********************************************************************/
     214        void xxGetFileName( const char * pPathFileName , std::string & rFileName ) const;
     215
     216        /***********************************************************************/
     217          /*!
     218           * \short Release the records
     219           */
     220        /***********************************************************************/
     221        void xxRelease();
     222
     223/***************************************************************************/
     224
     225};
     226
     227} // namespace Utilities
     228/***************************************************************************/
     229
     230
     231/** functions **************************************************************/
     232
     233/***************************************************************************/
     234  /*!
     235   * \short overload operator new to trace memory
     236   *
     237   * \param sz, size of memory to be newed
     238   * \param pFileName, indicates the file which calls new
     239   * \param nLine, indicates the line where new is called
     240   * \param bArray, whether with []
     241   *
     242   * \return pointer to the allocated memory
     243   */
     244/***************************************************************************/
     245void * operator new( size_t sz , char * pFileName , int nLine , bool bArray );
     246void * operator new [] ( size_t sz , char * pFileName , int nLine , bool bArray );
     247
     248/***************************************************************************/
     249  /*!
     250   * \short overload operator delete to trace memory
     251   *
     252   * \param pMemory, pointer to the memory to be deleted
     253   * \param pFileName, indicates the file which calls new
     254   * \param nLine, indicates the line where new is called
     255   * \param bArray, whether with []
     256   *
     257   * \return pointer to the allocated memory
     258   */
     259/***************************************************************************/
     260void operator delete( void * pMemory , char * pFileName , int nLine , bool bArray );
     261void operator delete [] ( void * pMemory , char * pFileName , int nLine , bool bArray );
     262
     263/***************************************************************************/
     264  /*!
     265   * \short template delete function
     266   *
     267   * \param p, pointer to the object to be deleted
     268   * \param pFileName, indicates the file which calls new
     269   * \param nLine, indicates the line where new is called
     270   * \param bArray, whether with []
     271   */
     272/***************************************************************************/
     273template <class T> inline
     274void Delete( T * p , char * pFileName , int nLine , bool bArray )
     275{
     276        {
     277                void * pSingle = ( void * )p;
     278                void * pArray = ( void * )( ( size_t )( pSingle ) - sizeof( int ) );
     279                extern Utilities::CMemoryTrace gMemoryTrace;
     280
     281                if( gMemoryTrace.HasBeenAllocated( pSingle ) == true )
     282                {
     283                        // by normal new
     284
     285                        // call the destructor of the object
     286                        p->~T();
     287
     288                        // delete the memory
     289                        operator delete( pSingle , pFileName , nLine , bArray );
     290                }
     291                else if( gMemoryTrace.HasBeenAllocated( pArray ) == true )
     292                {
     293                        // by new []
     294
     295                        // get the number of components
     296                        int nNumber = *( ( int * )pArray );
     297
     298                        // call the destructor for each object
     299                        for( ; nNumber > 0 ; nNumber-- , p++ )
     300                                p->~T();
     301
     302                        // delete the memory
     303                        operator delete [] ( pArray , pFileName , nLine , bArray );
     304                }
     305                else
     306                {
     307                        // not recorded memory allocation, do nothing but
     308                        // save the record by calling DelRecord()
     309                        gMemoryTrace.DelRecord( p , pFileName , nLine , bArray );
     310                }
     311        }
     312}
     313
     314/***************************************************************************/
     315  /*!
     316   * \short Output the information of memory tracing
     317   *
     318   * \param fpLog, pointer to log file
     319   */
     320/***************************************************************************/
     321void OutputMemTraceInfo(  FILE * fpLog );
     322
     323/***************************************************************************/
     324
     325/** definitions ************************************************************/
     326#define MEMNEW                          new (__FILE__ , __LINE__ , false )
     327#define MEMNEWARRAY                     new (__FILE__ , __LINE__ , true )
     328#define MEMDELETE(p)            Delete( ( p ) , __FILE__ , __LINE__ , false )
     329#define MEMDELETEARRAY(p)       Delete( ( p ) , __FILE__ , __LINE__ , true )
     330#define MEMTRACEINFO(p)         OutputMemTraceInfo(p)
     331/***************************************************************************/
     332
     333#else 
     334
     335/** definitions ************************************************************/
     336// use default new and delete
     337#define MEMNEW                          new
     338#define MEMNEWARRAY                     new
     339#define MEMDELETE(p)            delete (p)
     340#define MEMDELETEARRAY(p)       delete [] (p)
     341#define MEMTRACEINFO(p) {}      // do nothing
     342/***************************************************************************/
     343
     344#endif // CTRL_USE_TRACEMEM
     345
     346/***************************************************************************/
     347  /*!
     348   * \short Get how much memory (peak value) has been allocated
     349   *
     350   * \return memory in MBytes
     351   */
     352/***************************************************************************/
     353double GetMaxMBMemAllocated();
     354
     355/***************************************************************************/
     356  /*!
     357   * \short Get how many times the memory allocation has been called
     358   *
     359   * \return the times of memory allocation
     360   */
     361/***************************************************************************/
     362double GetTimesMemAllocation();
     363
     364#endif //__TOOL_TRACEMEM_H__
     365
     366/****************************************************************************
     367    end-of-file
     368****************************************************************************/
  • source/Lib/TLibDecoder/TDecBinCoderPIPE.cpp

     
    3535
    3636#include "TDecBinCoderPIPE.h"
    3737
     38#include "../TLibCommon/tool_tracemem.h"
    3839
    3940#if PIPE_LOW_DELAY_OPTION
    4041V2VDecoder::V2VDecoder( const UInt uiPIPEId, UInt* puiMaxDelayBitCounter )
     
    117118  for( UInt uiIdx = 0; uiIdx < NUM_V2V_CODERS; uiIdx++ )
    118119  {
    119120#if PIPE_LOW_DELAY_OPTION
    120     m_apcV2VDecoders[ uiIdx ] = new V2VDecoder( uiIdx, &m_uiMaxDelayBitCounter );
     121    m_apcV2VDecoders[ uiIdx ] = MEMNEW V2VDecoder( uiIdx, &m_uiMaxDelayBitCounter );
    121122#else
    122     m_apcV2VDecoders[ uiIdx ] = new V2VDecoder( uiIdx );
     123    m_apcV2VDecoders[ uiIdx ] = MEMNEW V2VDecoder( uiIdx );
    123124#endif
    124125  }
    125126}
     
    128129{
    129130  for( UInt uiIdx = 0; uiIdx < NUM_V2V_CODERS; uiIdx++ )
    130131  {
    131     delete m_apcV2VDecoders[ uiIdx ];
     132    MEMDELETE( m_apcV2VDecoders[ uiIdx ] );
    132133  }
    133134}
    134135
  • source/Lib/TLibDecoder/TDecBinCoderV2VwLB.h

     
    4343#include "TDecBinCoder.h"
    4444#include "TDecV2VTrees.h"
    4545
     46#include "../TLibCommon/tool_tracemem.h"
     47
    4648class TDecClearBit : public TDecBinIf {
    4749
    4850public:
     
    170172    virtual Void decodeBinTrm ( UInt& bit ) { bit = retrieveBit(mergedStatesMapping[62]); }
    171173
    172174public:
    173     TDecClearBuffer() { temp_space = new UChar[TEMP_SIZE]; }
    174     ~TDecClearBuffer() { delete [] temp_space; }
     175    TDecClearBuffer() { temp_space = MEMNEWARRAY UChar[TEMP_SIZE]; }
     176    ~TDecClearBuffer() { MEMDELETEARRAY( temp_space ); }
    175177
    176178};
    177179
  • source/Lib/TLibDecoder/TDecCu.cpp

     
    3535
    3636#include "TDecCu.h"
    3737
     38#include "../TLibCommon/tool_tracemem.h"
     39
    3840// ====================================================================================================================
    3941// Constructor / destructor / create / destroy
    4042// ====================================================================================================================
     
    6567{
    6668  m_uiMaxDepth = uiMaxDepth+1;
    6769
    68   m_ppcYuvResi = new TComYuv*[m_uiMaxDepth-1];
    69   m_ppcYuvReco = new TComYuv*[m_uiMaxDepth-1];
    70   m_ppcCU      = new TComDataCU*[m_uiMaxDepth-1];
     70  m_ppcYuvResi = MEMNEWARRAY TComYuv*[m_uiMaxDepth-1];
     71  m_ppcYuvReco = MEMNEWARRAY TComYuv*[m_uiMaxDepth-1];
     72  m_ppcCU      = MEMNEWARRAY TComDataCU*[m_uiMaxDepth-1];
    7173
    7274  UInt uiNumPartitions;
    7375  for ( UInt ui = 0; ui < m_uiMaxDepth-1; ui++ )
     
    7678    UInt uiWidth  = uiMaxWidth  >> ui;
    7779    UInt uiHeight = uiMaxHeight >> ui;
    7880
    79     m_ppcYuvResi[ui] = new TComYuv;    m_ppcYuvResi[ui]->create( uiWidth, uiHeight );
    80     m_ppcYuvReco[ui] = new TComYuv;    m_ppcYuvReco[ui]->create( uiWidth, uiHeight );
    81     m_ppcCU     [ui] = new TComDataCU; m_ppcCU     [ui]->create( uiNumPartitions, uiWidth, uiHeight, true );
     81    m_ppcYuvResi[ui] = MEMNEW TComYuv;    m_ppcYuvResi[ui]->create( uiWidth, uiHeight );
     82    m_ppcYuvReco[ui] = MEMNEW TComYuv;    m_ppcYuvReco[ui]->create( uiWidth, uiHeight );
     83    m_ppcCU     [ui] = MEMNEW TComDataCU; m_ppcCU     [ui]->create( uiNumPartitions, uiWidth, uiHeight, true );
    8284  }
    8385
    8486  // initialize partition order.
     
    9496{
    9597  for ( UInt ui = 0; ui < m_uiMaxDepth-1; ui++ )
    9698  {
    97     m_ppcYuvResi[ui]->destroy(); delete m_ppcYuvResi[ui]; m_ppcYuvResi[ui] = NULL;
    98     m_ppcYuvReco[ui]->destroy(); delete m_ppcYuvReco[ui]; m_ppcYuvReco[ui] = NULL;
    99     m_ppcCU     [ui]->destroy(); delete m_ppcCU     [ui]; m_ppcCU     [ui] = NULL;
     99    m_ppcYuvResi[ui]->destroy(); MEMDELETE( m_ppcYuvResi[ui] ); m_ppcYuvResi[ui] = NULL;
     100    m_ppcYuvReco[ui]->destroy(); MEMDELETE( m_ppcYuvReco[ui] ); m_ppcYuvReco[ui] = NULL;
     101    m_ppcCU     [ui]->destroy(); MEMDELETE( m_ppcCU     [ui] ); m_ppcCU     [ui] = NULL;
    100102  }
    101103
    102   delete [] m_ppcYuvResi; m_ppcYuvResi = NULL;
    103   delete [] m_ppcYuvReco; m_ppcYuvReco = NULL;
    104   delete [] m_ppcCU     ; m_ppcCU      = NULL;
     104  MEMDELETEARRAY( m_ppcYuvResi ); m_ppcYuvResi = NULL;
     105  MEMDELETEARRAY( m_ppcYuvReco ); m_ppcYuvReco = NULL;
     106  MEMDELETEARRAY( m_ppcCU      ); m_ppcCU      = NULL;
    105107}
    106108
    107109// ====================================================================================================================
  • source/Lib/TLibDecoder/TDecEntropy.cpp

     
    198198    m_pcEntropyDecoderIf->setMaxAlfCtrlDepth(uiSymbol);
    199199    if( pAlfParam->bSeparateQt )
    200200    {
    201       pAlfParam->pcQuadTree = new TComPicSym();
     201      pAlfParam->pcQuadTree = MEMNEW TComPicSym();
    202202      pAlfParam->pcQuadTree->create( pcPic->getPicYuvRec()->getWidth(), pcPic->getPicYuvRec()->getHeight(),  g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
    203203      for( UInt uiCUAddr = 0; uiCUAddr < pAlfParam->pcQuadTree->getNumberOfCUsInFrame(); uiCUAddr++ )
    204204      {
  • source/Lib/TLibDecoder/TDecGop.cpp

     
    185185
    186186  Double dDecTime = (double)(clock()-iBeforeTime) / CLOCKS_PER_SEC;
    187187  printf ("[DT %6.3f] ", dDecTime );
     188  printf( "[MA %.1lf MB, %.1lf KTimes] " , GetMaxMBMemAllocated() , GetTimesMemAllocation() / 1000 );
    188189
    189190  for (Int iRefList = 0; iRefList < 2; iRefList++)
    190191  {
  • source/Lib/TLibDecoder/TDecSlice.cpp

     
    3535
    3636#include "TDecSlice.h"
    3737
     38#include "../TLibCommon/tool_tracemem.h"
     39
    3840//////////////////////////////////////////////////////////////////////
    3941// Construction/Destruction
    4042//////////////////////////////////////////////////////////////////////
     
    6062  {
    6163    if(m_apcVirtPic[j][i] == NULL)
    6264    {
    63       m_apcVirtPic[j][i] = new TComPic;
     65      m_apcVirtPic[j][i] = MEMNEW TComPic;
    6466      m_apcVirtPic[j][i]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, true );
    6567    }
    6668  }
     
    7577    if(m_apcVirtPic[j][i])
    7678    {
    7779      m_apcVirtPic[j][i]->destroy();
    78       delete m_apcVirtPic[j][i];
     80      MEMDELETE( m_apcVirtPic[j][i] );
    7981      m_apcVirtPic[j][i]=NULL;
    8082    }
    8183  }
  • source/Lib/TLibDecoder/TDecTop.cpp

     
    3535
    3636#include "TDecTop.h"
    3737
     38#include "../TLibCommon/tool_tracemem.h"
     39
    3840TDecTop::TDecTop()
    3941{
    4042  m_iGopSize      = 0;
     
    6264Void TDecTop::create()
    6365{
    6466  m_cGopDecoder.create();
    65   m_apcSlicePilot = new TComSlice;
     67  m_apcSlicePilot = MEMNEW TComSlice;
    6668}
    6769
    6870Void TDecTop::destroy()
    6971{
    7072  m_cGopDecoder.destroy();
    7173
    72   delete m_apcSlicePilot;
     74  MEMDELETE( m_apcSlicePilot );
    7375  m_apcSlicePilot = NULL;
    7476
    7577  m_cSliceDecoder.destroy();
     
    9597    TComPic* pcPic = *(iterPic++);
    9698    pcPic->destroy();
    9799
    98     delete pcPic;
     100    MEMDELETE( pcPic );
    99101    pcPic = NULL;
    100102  }
    101103
     
    129131
    130132  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
    131133  {
    132     rpcPic = new TComPic;
     134    rpcPic = MEMNEW TComPic;
    133135
    134136    rpcPic->create ( pcSlice->getSPS()->getWidth(), pcSlice->getSPS()->getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true);
    135137    m_cListPic.pushBack( rpcPic );
  • source/Lib/TLibEncoder/TEncAdaptiveLoopFilter.cpp

     
    3838#include <stdio.h>
    3939#include <math.h>
    4040
     41#include "../TLibCommon/tool_tracemem.h"
     42
    4143// ====================================================================================================================
    4244// Constants
    4345// ====================================================================================================================
     
    7779{
    7880  m_pcPic = pcPic;
    7981  m_pcEntropyCoder = pcEntropyCoder;
    80   m_pcCoderFixedBits = new TComBitCounter;
     82  m_pcCoderFixedBits = MEMNEW TComBitCounter;
    8183  m_pcEntropyCoder->setBitstream( m_pcCoderFixedBits );
    8284  m_pppcRDSbacCoder = pppcRDSbacCoder;
    8385  m_pcRDGoOnSbacCoder = pcRDGoOnSbacCoder;
     
    105107  Int iWidth  = pcPic->getPicYuvOrg()->getWidth();
    106108  Int iHeight = pcPic->getPicYuvOrg()->getHeight();
    107109
    108   m_pcPicYuvTmp = new TComPicYuv();
     110  m_pcPicYuvTmp = MEMNEW TComPicYuv();
    109111  m_pcPicYuvTmp->create(iWidth, iHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth);
    110112
    111   m_pcPicYuvFiltered = new TComPicYuv();
     113  m_pcPicYuvFiltered = MEMNEW TComPicYuv();
    112114  m_pcPicYuvFiltered->create(iWidth, iHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth);
    113115
    114116  m_pcPicYuvBest = pcPic->getPicYuvPred();
    115117
    116   m_pcBestAlfParam = new ALFParam;
    117   m_pcTempAlfParam = new ALFParam;
     118  m_pcBestAlfParam = MEMNEW ALFParam;
     119  m_pcTempAlfParam = MEMNEW ALFParam;
    118120  allocALFParam(m_pcBestAlfParam);
    119121  allocALFParam(m_pcTempAlfParam);
    120122}
     
    125127  xUninitParam();
    126128
    127129  m_pcPicYuvFiltered->destroy() ;
    128   delete m_pcPicYuvFiltered ;
     130  MEMDELETE( m_pcPicYuvFiltered ) ;
    129131
    130132  m_pcPicYuvTmp->destroy();
    131   delete m_pcPicYuvTmp ;
     133  MEMDELETE( m_pcPicYuvTmp ) ;
    132134//  m_pcPicYuvTmp = NULL;
    133135  m_pcPic = NULL;
    134136  m_pcEntropyCoder = NULL;
    135   delete m_pcCoderFixedBits;
     137  MEMDELETE( m_pcCoderFixedBits );
    136138
    137139  freeALFParam(m_pcBestAlfParam);
    138140  freeALFParam(m_pcTempAlfParam);
    139   delete m_pcBestAlfParam ;
    140   delete m_pcTempAlfParam;
     141  MEMDELETE( m_pcBestAlfParam ) ;
     142  MEMDELETE( m_pcTempAlfParam );
    141143}
    142144
    143145/** \param  pcAlfParam          ALF parameter
     
    155157  TComPicYuv* pcPicOrg             = m_pcPic->getPicYuvOrg();
    156158  TComPicYuv* pcPicYuvRec          = m_pcPic->getPicYuvRec();
    157159
    158   TComPicYuv* pcPicYuvFiltered = new TComPicYuv ;
     160  TComPicYuv* pcPicYuvFiltered = MEMNEW TComPicYuv ;
    159161  pcPicYuvFiltered->create(pcPicOrg->getWidth(), pcPicOrg->getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ) ;
    160162
    161163  // set min cost
     
    229231  // store best depth
    230232  ruiMaxAlfCtrlDepth = m_pcEntropyCoder->getMaxAlfCtrlDepth();
    231233  pcPicYuvFiltered->destroy() ;
    232   delete pcPicYuvFiltered ;
     234  MEMDELETE( pcPicYuvFiltered ) ;
    233235}
    234236
    235237
     
    294296  UInt64 uiDist   ;
    295297  Double dCmpCost   = rdMinCost;
    296298 
    297   TComPicYuv* pcTmpPicVerticallyFiltered = new TComPicYuv;
    298   TComPicYuv* pcTmpPicHorizontallyFiltered = new TComPicYuv;
     299  TComPicYuv* pcTmpPicVerticallyFiltered = MEMNEW TComPicYuv;
     300  TComPicYuv* pcTmpPicHorizontallyFiltered = MEMNEW TComPicYuv;
    299301
    300302  pcTmpPicVerticallyFiltered->create(pcPicOrg->getWidth(), pcPicOrg->getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth) ;
    301303  pcTmpPicHorizontallyFiltered->create(pcPicOrg->getWidth(), pcPicOrg->getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth) ;
    302304
    303   ALFParam* pcTmpAlfParams = new ALFParam ;
     305  ALFParam* pcTmpAlfParams = MEMNEW ALFParam ;
    304306  allocALFParam( pcTmpAlfParams );
    305307
    306308  for(Int iPrevPlane=0; iPrevPlane<iPlane; iPrevPlane++)
     
    337339  }
    338340  pcTmpPicVerticallyFiltered->destroy() ;
    339341  pcTmpPicHorizontallyFiltered->destroy() ;
    340   delete pcTmpPicVerticallyFiltered ;
    341   delete pcTmpPicHorizontallyFiltered ;
     342  MEMDELETE( pcTmpPicVerticallyFiltered ) ;
     343  MEMDELETE( pcTmpPicHorizontallyFiltered ) ;
    342344  freeALFParam( pcTmpAlfParams );
    343   delete pcTmpAlfParams ;
     345  MEMDELETE( pcTmpAlfParams ) ;
    344346}
    345347
    346348Void TEncAdaptiveLoopFilter::xFilterTapDecision(TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicFiltered, ALFParam* pcAlfParams, UInt64& ruiMinRate, UInt64& ruiMinDist, Double& rdMinCost, Int iPlane)
     
    352354  // }
    353355  UInt64 uiTmpRate, uiTmpDist;
    354356  Double dTmpCost;
    355   TComPicYuv* pcTmpPicVerticallyFiltered = new TComPicYuv;
    356   TComPicYuv* pcTmpPicHorizontallyFiltered = new TComPicYuv;
    357   ALFParam* pcTmpAlfParams = new ALFParam ;
     357  TComPicYuv* pcTmpPicVerticallyFiltered = MEMNEW TComPicYuv;
     358  TComPicYuv* pcTmpPicHorizontallyFiltered = MEMNEW TComPicYuv;
     359  ALFParam* pcTmpAlfParams = MEMNEW ALFParam ;
    358360  allocALFParam( pcTmpAlfParams );
    359361
    360362
     
    402404  freeALFParam( pcTmpAlfParams );
    403405  pcTmpPicHorizontallyFiltered->destroy();
    404406  pcTmpPicVerticallyFiltered->destroy();
    405   delete pcTmpAlfParams;
    406   delete pcTmpPicHorizontallyFiltered ;
    407   delete pcTmpPicVerticallyFiltered ;
     407  MEMDELETE( pcTmpAlfParams );
     408  MEMDELETE( pcTmpPicHorizontallyFiltered ) ;
     409  MEMDELETE( pcTmpPicVerticallyFiltered ) ;
    408410
    409411}
    410412
     
    414416  m_pcEntropyCoder->setAlfCtrl(true);
    415417  UInt uiBestDepth = 0;
    416418
    417   ALFParam* pcTmpAlfParam = new ALFParam ;
     419  ALFParam* pcTmpAlfParam = MEMNEW ALFParam ;
    418420  allocALFParam(pcTmpAlfParam);
    419421  copyALFParam(pcTmpAlfParam, pcAlfParam);
    420422
    421   ALFParam* pcFrmAlfParam = new ALFParam ;
     423  ALFParam* pcFrmAlfParam = MEMNEW ALFParam ;
    422424  allocALFParam(pcFrmAlfParam);
    423425  copyALFParam(pcFrmAlfParam, pcAlfParam);
    424426
    425   TComPicYuv* pcFilteredFrm = new TComPicYuv();
     427  TComPicYuv* pcFilteredFrm = MEMNEW TComPicYuv();
    426428  pcFilteredFrm->create(pcPicOrg->getWidth(), pcPicOrg->getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth);
    427429  pcPicFiltered->copyToPic( pcFilteredFrm );
    428430
    429   TComPicYuv* pcTmpPicVerticallyFiltered = new TComPicYuv;
     431  TComPicYuv* pcTmpPicVerticallyFiltered = MEMNEW TComPicYuv;
    430432  pcTmpPicVerticallyFiltered->create(pcPicOrg->getWidth(), pcPicOrg->getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth);
    431   TComPicYuv* pcTmpPicHorizontallyFiltered = new TComPicYuv;
     433  TComPicYuv* pcTmpPicHorizontallyFiltered = MEMNEW TComPicYuv;
    432434  pcTmpPicHorizontallyFiltered->create(pcPicOrg->getWidth(), pcPicOrg->getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth);
    433435
    434436  TComPicSym* pcQuadTreeBest;
     
    436438  TComPicSym* pcQuadTreeHelp;
    437439  if( m_bALFSeparateQt )
    438440  {
    439     pcQuadTreeBest = new TComPicSym();
     441    pcQuadTreeBest = MEMNEW TComPicSym();
    440442    pcQuadTreeBest->create( pcPicDec->getWidth(), pcPicDec->getHeight(),  g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
    441     pcQuadTreeTmp = new TComPicSym();
     443    pcQuadTreeTmp = MEMNEW TComPicSym();
    442444    pcQuadTreeTmp->create( pcPicDec->getWidth(), pcPicDec->getHeight(),  g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
    443445    for( UInt uiCUAddr = 0; uiCUAddr < pcQuadTreeBest->getNumberOfCUsInFrame(); uiCUAddr++ )
    444446    {
     
    528530    if( m_bALFSeparateQt )
    529531    {
    530532      pcQuadTreeBest->destroy();
    531       delete pcQuadTreeBest;
     533      MEMDELETE( pcQuadTreeBest );
    532534    }
    533535  }
    534536
    535537  if( m_bALFSeparateQt)
    536538  {
    537539    pcQuadTreeTmp->destroy();
    538     delete pcQuadTreeTmp;
     540    MEMDELETE( pcQuadTreeTmp );
    539541  }
    540542  else
    541543  {
     
    543545  }
    544546
    545547  pcFilteredFrm->destroy();
    546   delete pcFilteredFrm;
     548  MEMDELETE( pcFilteredFrm );
    547549
    548550  //
    549551  freeALFParam(pcTmpAlfParam);
    550   delete pcTmpAlfParam ;
     552  MEMDELETE( pcTmpAlfParam  );
    551553  freeALFParam(pcFrmAlfParam);
    552   delete pcFrmAlfParam ;
     554  MEMDELETE( pcFrmAlfParam  );
    553555
    554556  pcTmpPicVerticallyFiltered->destroy() ;
    555   delete pcTmpPicVerticallyFiltered ;
     557  MEMDELETE( pcTmpPicVerticallyFiltered  );
    556558  pcTmpPicHorizontallyFiltered->destroy() ;
    557   delete pcTmpPicHorizontallyFiltered ;
     559  MEMDELETE( pcTmpPicHorizontallyFiltered  );
    558560
    559561}
    560562
     
    578580  }
    579581  else
    580582  {
    581     m_ppdAlfCorr = new Double*[ALF_MAX_NUM_COEF];
     583    m_ppdAlfCorr = MEMNEWARRAY Double*[ALF_MAX_NUM_COEF];
    582584    for (i = 0; i < ALF_MAX_NUM_COEF; i++)
    583585    {
    584       m_ppdAlfCorr[i] = new Double[ALF_MAX_NUM_COEF+1];
     586      m_ppdAlfCorr[i] = MEMNEWARRAY Double[ALF_MAX_NUM_COEF+1];
    585587      for (j = 0; j < ALF_MAX_NUM_COEF+1; j++)
    586588      {
    587589        m_ppdAlfCorr[i][j] = 0;
     
    607609  }
    608610  else
    609611  {
    610     m_puiCUVerticalCorr = new UInt***[m_pcPic->getNumCUsInFrame()];
     612    m_puiCUVerticalCorr = MEMNEWARRAY UInt***[m_pcPic->getNumCUsInFrame()];
    611613    for (i = 0; i < m_pcPic->getNumCUsInFrame(); i++)
    612614    {
    613       m_puiCUVerticalCorr[i] = new UInt**[m_uiNumSCUInCU];
     615      m_puiCUVerticalCorr[i] = MEMNEWARRAY UInt**[m_uiNumSCUInCU];
    614616      for (j = 0; j < m_uiNumSCUInCU; j++)
    615617      {
    616         m_puiCUVerticalCorr[i][j] = new UInt*[ALF_MAX_NUM_COEF];
     618        m_puiCUVerticalCorr[i][j] = MEMNEWARRAY UInt*[ALF_MAX_NUM_COEF];
    617619        for (k = 0; k < ALF_MAX_NUM_COEF; k++)
    618620        {
    619           m_puiCUVerticalCorr[i][j][k] = new UInt[ALF_MAX_NUM_COEF+1];
     621          m_puiCUVerticalCorr[i][j][k] = MEMNEWARRAY UInt[ALF_MAX_NUM_COEF+1];
    620622          for (l = 0; l< ALF_MAX_NUM_COEF+1; l++)
    621623          {
    622624            m_puiCUVerticalCorr[i][j][k][l] = 0;
     
    645647  }
    646648  else
    647649  {
    648     m_puiCUHorizontalCorr = new UInt***[m_pcPic->getNumCUsInFrame()];
     650    m_puiCUHorizontalCorr = MEMNEWARRAY UInt***[m_pcPic->getNumCUsInFrame()];
    649651    for (i = 0; i < m_pcPic->getNumCUsInFrame(); i++)
    650652    {
    651       m_puiCUHorizontalCorr[i] = new UInt**[m_uiNumSCUInCU];
     653      m_puiCUHorizontalCorr[i] = MEMNEWARRAY UInt**[m_uiNumSCUInCU];
    652654      for (j = 0; j < m_uiNumSCUInCU; j++)
    653655      {
    654         m_puiCUHorizontalCorr[i][j] = new UInt*[ALF_MAX_NUM_COEF];
     656        m_puiCUHorizontalCorr[i][j] = MEMNEWARRAY UInt*[ALF_MAX_NUM_COEF];
    655657        for (k = 0; k < ALF_MAX_NUM_COEF; k++)
    656658        {
    657           m_puiCUHorizontalCorr[i][j][k] = new UInt[ALF_MAX_NUM_COEF+1];
     659          m_puiCUHorizontalCorr[i][j][k] = MEMNEWARRAY UInt[ALF_MAX_NUM_COEF+1];
    658660          for (l = 0; l< ALF_MAX_NUM_COEF+1; l++)
    659661          {
    660662            m_puiCUHorizontalCorr[i][j][k][l] = 0;
     
    674676  }
    675677  else
    676678  {
    677     m_pdDoubleAlfCoeff = new Double[ALF_MAX_NUM_COEF];
     679    m_pdDoubleAlfCoeff = MEMNEWARRAY Double[ALF_MAX_NUM_COEF];
    678680    for (i = 0; i < ALF_MAX_NUM_COEF; i++)
    679681    {
    680682      m_pdDoubleAlfCoeff[i] = 0;
     
    690692  {
    691693    for (i = 0; i < ALF_MAX_NUM_COEF; i++)
    692694    {
    693       delete[] m_ppdAlfCorr[i];
     695      MEMDELETEARRAY( m_ppdAlfCorr[i] );
    694696      m_ppdAlfCorr[i] = NULL;
    695697    }
    696     delete[] m_ppdAlfCorr;
     698    MEMDELETEARRAY( m_ppdAlfCorr );
    697699    m_ppdAlfCorr = NULL;
    698700  }
    699701
     
    705707      {
    706708        for (k = 0; k < ALF_MAX_NUM_COEF; k++)
    707709        {
    708           delete[] m_puiCUVerticalCorr[i][j][k];
     710          MEMDELETEARRAY( m_puiCUVerticalCorr[i][j][k] );
    709711          m_puiCUVerticalCorr[i][j][k] = NULL;
    710712        }
    711         delete[] m_puiCUVerticalCorr[i][j];
     713        MEMDELETEARRAY( m_puiCUVerticalCorr[i][j] );
    712714        m_puiCUVerticalCorr[i][j] = NULL;
    713715      }
    714       delete[] m_puiCUVerticalCorr[i];
     716      MEMDELETEARRAY( m_puiCUVerticalCorr[i] );
    715717      m_puiCUVerticalCorr[i] = NULL;
    716718    }
    717     delete[] m_puiCUVerticalCorr;
     719    MEMDELETEARRAY( m_puiCUVerticalCorr );
    718720    m_puiCUVerticalCorr = NULL;
    719721  }
    720722
     
    726728        {
    727729          for (k = 0; k < ALF_MAX_NUM_COEF; k++)
    728730          {
    729             delete[] m_puiCUHorizontalCorr[i][j][k];
     731            MEMDELETEARRAY( m_puiCUHorizontalCorr[i][j][k] );
    730732            m_puiCUHorizontalCorr[i][j][k] = NULL;
    731733          }
    732           delete[] m_puiCUHorizontalCorr[i][j];
     734          MEMDELETEARRAY( m_puiCUHorizontalCorr[i][j] );
    733735          m_puiCUHorizontalCorr[i][j] = NULL;
    734736        }
    735         delete[] m_puiCUHorizontalCorr[i];
     737        MEMDELETEARRAY( m_puiCUHorizontalCorr[i] );
    736738        m_puiCUHorizontalCorr[i] = NULL;
    737739      }
    738       delete[] m_puiCUHorizontalCorr;
     740      MEMDELETEARRAY( m_puiCUHorizontalCorr );
    739741      m_puiCUHorizontalCorr = NULL;
    740742    }
    741743
    742744
    743745  if (m_pdDoubleAlfCoeff != NULL)
    744746  {
    745     delete[] m_pdDoubleAlfCoeff;
     747    MEMDELETEARRAY( m_pdDoubleAlfCoeff );
    746748    m_pdDoubleAlfCoeff = NULL;
    747749  }
    748750}
     
    10541056
    10551057  Int* aiQuantCoeffs = rcFilter.aiQuantFilterCoeffs;
    10561058
    1057   Double* adDelta   = new Double[ iNumCoeffs+1 ];
    1058   Int*    aiPosIndx = new Int   [ iNumCoeffs+1 ];
     1059  Double* adDelta   = MEMNEWARRAY Double[ iNumCoeffs+1 ];
     1060  Int*    aiPosIndx = MEMNEWARRAY Int   [ iNumCoeffs+1 ];
    10591061
    10601062
    10611063  dGainNotQuant = 0.0;
     
    11201122    aiQuantCoeffs[i] = Max( iMinValue , Min( iMaxValue , aiQuantCoeffs[i] ) );
    11211123  }
    11221124
    1123   delete[] adDelta;
     1125  MEMDELETEARRAY( adDelta );
    11241126  adDelta = NULL;
    11251127
    1126   delete[] aiPosIndx;
     1128  MEMDELETEARRAY( aiPosIndx );
    11271129  aiPosIndx = NULL;
    11281130}
    11291131
     
    11391141{
    11401142  if(pAlfParam != NULL)
    11411143  {
    1142     ALFParam* pcTempAlfParams = new ALFParam ;
     1144    ALFParam* pcTempAlfParams = MEMNEW ALFParam ;
    11431145    allocALFParam( pcTempAlfParams );
    11441146    copyALFParam(pcTempAlfParams, pAlfParam);
    11451147    xPredictALFCoeff(pcTempAlfParams, 0 );
     
    11531155
    11541156    m_pcEntropyCoder->encodeAlfParam( pcTempAlfParams );
    11551157    freeALFParam( pcTempAlfParams );
    1156     delete pcTempAlfParams ;
     1158    MEMDELETE( pcTempAlfParams  );
    11571159    ruiRate = m_pcEntropyCoder->getNumberOfWrittenBits();
    11581160  }
    11591161  else
     
    11671169{
    11681170  if(pAlfParam != NULL)
    11691171  {
    1170     ALFParam* pcTempAlfParams = new ALFParam ;
     1172    ALFParam* pcTempAlfParams = MEMNEW ALFParam ;
    11711173    allocALFParam( pcTempAlfParams );
    11721174    copyALFParam(pcTempAlfParams, pAlfParam);
    11731175    xPredictALFCoeff(pcTempAlfParams, iPlane );
     
    11751177    m_pcEntropyCoder->resetBits();
    11761178    m_pcEntropyCoder->encodeAlfParam(pcTempAlfParams);
    11771179    freeALFParam( pcTempAlfParams );
    1178     delete pcTempAlfParams ;
     1180    MEMDELETE( pcTempAlfParams  );
    11791181
    11801182    if(pAlfParam->cu_control_flag)
    11811183    {
     
    14001402    }
    14011403    UInt64* auiFixedBitsCurrBest;
    14021404    UInt64* auiFixedBitsNextBest;
    1403     auiFixedBitsCurrBest = new UInt64[MAX_CU_DEPTH];
    1404     auiFixedBitsNextBest = new UInt64[MAX_CU_DEPTH];
     1405    auiFixedBitsCurrBest = MEMNEWARRAY UInt64[MAX_CU_DEPTH];
     1406    auiFixedBitsNextBest = MEMNEWARRAY UInt64[MAX_CU_DEPTH];
    14051407    ::memset( auiFixedBitsCurrBest , 0 , sizeof(UInt64) * MAX_CU_DEPTH );
    14061408    ::memset( auiFixedBitsNextBest , 0 , sizeof(UInt64) * MAX_CU_DEPTH );
    14071409    for( UInt uiCUAddr = 0; uiCUAddr < pcQuadTree->getNumberOfCUsInFrame() ; uiCUAddr++ )
     
    14201422      m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[0][CI_NEXT_BEST] );
    14211423    }
    14221424    ruiRate = auiFixedBitsNextBest[0] + m_pcEntropyCoder->getNumberOfWrittenBits() ;
    1423     delete[] auiFixedBitsCurrBest;
    1424     delete[] auiFixedBitsNextBest;
     1425    MEMDELETEARRAY( auiFixedBitsCurrBest );
     1426    MEMDELETEARRAY( auiFixedBitsNextBest );
    14251427  }
    14261428  else
    14271429  {
     
    19731975  Int iWidth = pcPic->getPicYuvOrg()->getWidth();
    19741976  Int iHeight = pcPic->getPicYuvOrg()->getHeight();
    19751977
    1976   m_pcPicYuvTmp = new TComPicYuv();
     1978  m_pcPicYuvTmp = MEMNEW TComPicYuv();
    19771979  m_pcPicYuvTmp->createLuma(iWidth, iHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth);
    19781980  m_pcPicYuvBest = pcPic->getPicYuvPred();
    19791981
    1980   m_pcBestAlfParam = new ALFParam;
    1981   m_pcTempAlfParam = new ALFParam;
     1982  m_pcBestAlfParam = MEMNEW ALFParam;
     1983  m_pcTempAlfParam = MEMNEW ALFParam;
    19821984  allocALFParam(m_pcBestAlfParam);
    19831985  allocALFParam(m_pcTempAlfParam);
    19841986#if QC_ALF
     
    20052007  get_mem2Dpel(&maskImg, im_height, im_width);
    20062008 
    20072009//  InitALFGlobalBuffers (iWidth, iHeight);
    2008   ALFp = new ALFParam;
    2009   tempALFp = new ALFParam;
     2010  ALFp = MEMNEW ALFParam;
     2011  tempALFp = MEMNEW ALFParam;
    20102012  allocALFParam(ALFp);
    20112013  allocALFParam(tempALFp);
    20122014  m_pcDummyEntropyCoder = m_pcEntropyCoder;
     
    20192021  xDestroyTmpAlfCtrlFlags();
    20202022
    20212023  m_pcPicYuvTmp->destroyLuma();
    2022   delete m_pcPicYuvTmp;
     2024  MEMDELETE( m_pcPicYuvTmp );
    20232025  m_pcPicYuvTmp = NULL;
    20242026  m_pcPic = NULL;
    20252027  m_pcEntropyCoder = NULL;
    20262028
    20272029  freeALFParam(m_pcBestAlfParam);
    20282030  freeALFParam(m_pcTempAlfParam);
    2029   delete m_pcBestAlfParam;
    2030   delete m_pcTempAlfParam;
     2031  MEMDELETE( m_pcBestAlfParam );
     2032  MEMDELETE( m_pcTempAlfParam );
    20312033#if QC_ALF
    20322034  free_mem2Dpel (imgY_rec);
    20332035  free_mem2Dpel (imgY_org);
     
    20502052  //  FreeALFGlobalBurrers();
    20512053  freeALFParam(ALFp);
    20522054  freeALFParam(tempALFp);
    2053   delete ALFp;
    2054   delete tempALFp;
     2055  MEMDELETE( ALFp );
     2056  MEMDELETE( tempALFp );
    20552057#endif
    20562058}
    20572059
     
    24422444  }
    24432445  else
    24442446  {
    2445     m_ppdAlfCorr = new Double*[ALF_MAX_NUM_COEF];
     2447    m_ppdAlfCorr = MEMNEWARRAY Double*[ALF_MAX_NUM_COEF];
    24462448    for (i = 0; i < ALF_MAX_NUM_COEF; i++)
    24472449    {
    2448       m_ppdAlfCorr[i] = new Double[ALF_MAX_NUM_COEF+1];
     2450      m_ppdAlfCorr[i] = MEMNEWARRAY Double[ALF_MAX_NUM_COEF+1];
    24492451      for (j = 0; j < ALF_MAX_NUM_COEF+1; j++)
    24502452      {
    24512453        m_ppdAlfCorr[i][j] = 0;
     
    24712473  }
    24722474  else
    24732475  {
    2474     m_puiCUCorr = new CorrBlk*[m_pcPic->getNumCUsInFrame()];
     2476    m_puiCUCorr = MEMNEWARRAY CorrBlk*[m_pcPic->getNumCUsInFrame()];
    24752477    for (i = 0; i < m_pcPic->getNumCUsInFrame(); i++)
    24762478    {
    2477       m_puiCUCorr[i] = new CorrBlk[m_uiNumSCUInCU];
     2479      m_puiCUCorr[i] = MEMNEWARRAY CorrBlk[m_uiNumSCUInCU];
    24782480
    24792481      for (j = 0; j < m_uiNumSCUInCU; j++)
    24802482      {
     
    24982500  }
    24992501  else
    25002502  {
    2501     m_pdDoubleAlfCoeff = new Double[ALF_MAX_NUM_COEF];
     2503    m_pdDoubleAlfCoeff = MEMNEWARRAY Double[ALF_MAX_NUM_COEF];
    25022504    for (i = 0; i < ALF_MAX_NUM_COEF; i++)
    25032505    {
    25042506      m_pdDoubleAlfCoeff[i] = 0;
     
    25142516  {
    25152517    for (i = 0; i < ALF_MAX_NUM_COEF; i++)
    25162518    {
    2517       delete[] m_ppdAlfCorr[i];
     2519      MEMDELETEARRAY( m_ppdAlfCorr[i] );
    25182520      m_ppdAlfCorr[i] = NULL;
    25192521    }
    2520     delete[] m_ppdAlfCorr;
     2522    MEMDELETEARRAY( m_ppdAlfCorr );
    25212523    m_ppdAlfCorr = NULL;
    25222524  }
    25232525
     
    25252527  {
    25262528    for (i = 0; i < m_pcPic->getNumCUsInFrame(); i++)
    25272529    {
    2528       delete[] m_puiCUCorr[i];
     2530      MEMDELETEARRAY( m_puiCUCorr[i] );
    25292531      m_puiCUCorr[i] = NULL;
    25302532    }
    2531     delete[] m_puiCUCorr;
     2533    MEMDELETEARRAY( m_puiCUCorr );
    25322534    m_puiCUCorr = NULL;
    25332535  }
    25342536
    25352537  if (m_pdDoubleAlfCoeff != NULL)
    25362538  {
    2537     delete[] m_pdDoubleAlfCoeff;
     2539    MEMDELETEARRAY( m_pdDoubleAlfCoeff );
    25382540    m_pdDoubleAlfCoeff = NULL;
    25392541  }
    25402542}
     
    27052707    break;
    27062708  }
    27072709
    2708   UInt* pTerm = new UInt[N];
     2710  UInt* pTerm = MEMNEWARRAY UInt[N];
    27092711
    27102712  Int i, j;
    27112713
     
    27402742    }
    27412743  }
    27422744
    2743   delete[] pTerm;
     2745  MEMDELETEARRAY( pTerm );
    27442746  pTerm = NULL;
    27452747}
    27462748
     
    27712773    break;
    27722774  }
    27732775
    2774   Pel* pTerm = new Pel[N];
     2776  Pel* pTerm = MEMNEWARRAY Pel[N];
    27752777
    27762778  Int i, j;
    27772779
     
    28122814    for(i=j+1; i<N; i++)
    28132815      m_ppdAlfCorr[i][j] = m_ppdAlfCorr[j][i];
    28142816
    2815   delete[] pTerm;
     2817  MEMDELETEARRAY( pTerm );
    28162818  pTerm = NULL;
    28172819}
    28182820
     
    28432845    break;
    28442846  }
    28452847
    2846   Pel* pTerm = new Pel[N];
     2848  Pel* pTerm = MEMNEWARRAY Pel[N];
    28472849
    28482850  Int i, j;
    28492851
     
    28802882    }
    28812883  }
    28822884
    2883   delete[] pTerm;
     2885  MEMDELETEARRAY( pTerm );
    28842886  pTerm = NULL;
    28852887}
    28862888
     
    29983000
    29993001  N = (tap*tap+1)>>1;
    30003002
    3001   dh = new Double[N];
    3002   nc = new Int[N];
     3003  dh = MEMNEWARRAY Double[N];
     3004  nc = MEMNEWARRAY Int[N];
    30033005
    30043006  max_value =   (1<<(1+ALF_NUM_BIT_SHIFT))-1;
    30053007  min_value = 0-(1<<(1+ALF_NUM_BIT_SHIFT));
     
    30873089  qh[N] =  (h[N]>=0.0)? (Int)( h[N]*(1<<(ALF_NUM_BIT_SHIFT-bit_depth+8)) + 0.5) : -(Int)(-h[N]*(1<<(ALF_NUM_BIT_SHIFT-bit_depth+8)) + 0.5);
    30883090  qh[N] = Max(min_value,Min(max_value, qh[N]));
    30893091
    3090   delete[] dh;
     3092  MEMDELETEARRAY( dh );
    30913093  dh = NULL;
    30923094
    3093   delete[] nc;
     3095  MEMDELETEARRAY( nc );
    30943096  nc = NULL;
    30953097}
    30963098
     
    31083110  if(pAlfParam != NULL)
    31093111  {
    31103112    Int* piTmpCoef;
    3111     piTmpCoef = new Int[ALF_MAX_NUM_COEF];
     3113    piTmpCoef = MEMNEWARRAY Int[ALF_MAX_NUM_COEF];
    31123114
    31133115    memcpy(piTmpCoef, pAlfParam->coeff, sizeof(Int)*pAlfParam->num_coeff);
    31143116
     
    31243126    }
    31253127    ruiRate = m_pcEntropyCoder->getNumberOfWrittenBits();
    31263128    memcpy(pAlfParam->coeff, piTmpCoef, sizeof(int)*pAlfParam->num_coeff);
    3127     delete[] piTmpCoef;
     3129    MEMDELETEARRAY( piTmpCoef );
    31283130    piTmpCoef = NULL;
    31293131  }
    31303132  else
     
    31403142  if(pAlfParam != NULL)
    31413143  {
    31423144    Int* piTmpCoef;
    3143     piTmpCoef = new Int[ALF_MAX_NUM_COEF];
     3145    piTmpCoef = MEMNEWARRAY Int[ALF_MAX_NUM_COEF];
    31443146
    31453147    memcpy(piTmpCoef, pAlfParam->coeff, sizeof(Int)*pAlfParam->num_coeff);
    31463148
     
    31563158    }
    31573159    ruiRate = m_pcEntropyCoder->getNumberOfWrittenBits();
    31583160    memcpy(pAlfParam->coeff, piTmpCoef, sizeof(int)*pAlfParam->num_coeff);
    3159     delete[] piTmpCoef;
     3161    MEMDELETEARRAY( piTmpCoef );
    31603162    piTmpCoef = NULL;
    31613163  }
    31623164  else
     
    31733175  if(pAlfParam->chroma_idc)
    31743176  {
    31753177    Int* piTmpCoef;
    3176     piTmpCoef = new Int[ALF_MAX_NUM_COEF_C];
     3178    piTmpCoef = MEMNEWARRAY Int[ALF_MAX_NUM_COEF_C];
    31773179
    31783180    memcpy(piTmpCoef, pAlfParam->coeff_chroma, sizeof(Int)*pAlfParam->num_coeff_chroma);
    31793181
     
    31893191    }
    31903192    ruiRate = m_pcEntropyCoder->getNumberOfWrittenBits();
    31913193    memcpy(pAlfParam->coeff_chroma, piTmpCoef, sizeof(int)*pAlfParam->num_coeff_chroma);
    3192     delete[] piTmpCoef;
     3194    MEMDELETEARRAY( piTmpCoef );
    31933195    piTmpCoef = NULL;
    31943196  }
    31953197  ruiDist = 0;
  • source/Lib/TLibEncoder/TEncBinCoderPIPE.cpp

     
    3535
    3636#include "TEncBinCoderPIPE.h"
    3737
     38#include "../TLibCommon/tool_tracemem.h"
    3839
    3940#define INVALID  UInt(-1)
    4041
     
    8889CodewordBuffer::CodewordBuffer()
    8990: m_pcTComBitIf       ( 0 )
    9091, m_uiBufferSize      ( INIT_CODEWORD_BUFFER_SIZE )
    91 , m_pacCodewordBuffer ( new CBufEntry [ m_uiBufferSize ] )
     92, m_pacCodewordBuffer ( MEMNEWARRAY CBufEntry [ m_uiBufferSize ] )
    9293#if PIPE_LOW_DELAY_OPTION
    9394, m_papcV2VEncoders   ( 0 )
    9495#endif
     
    9798
    9899CodewordBuffer::~CodewordBuffer()
    99100{
    100   delete [] m_pacCodewordBuffer;
     101  MEMDELETEARRAY( m_pacCodewordBuffer );
    101102}
    102103
    103104#if PIPE_LOW_DELAY_OPTION
     
    190191  UInt              uiNewBufferSize       = m_uiBufferSize      + m_uiBufferSize;
    191192  UInt              uiNewNextWriteIdx     = 0;
    192193  UInt              uiNewNextReservedIdx  = m_uiBufferSize      - m_uiNumFreeEntries;
    193   CBufEntry*        pacNewCodewordBuffer  = new CBufEntry       [ uiNewBufferSize ];
     194  CBufEntry*        pacNewCodewordBuffer  = MEMNEWARRAY CBufEntry       [ uiNewBufferSize ];
    194195  for( UInt uiSrcIdx = m_uiNextWriteIdx, uiDesIdx = uiNewNextWriteIdx; uiDesIdx < uiNewNextReservedIdx; uiDesIdx++, uiSrcIdx = ( uiSrcIdx + 1 ) % m_uiBufferSize )
    195196  {
    196197    pacNewCodewordBuffer[ uiDesIdx ] = m_pacCodewordBuffer[ uiSrcIdx ];
     
    203204  {
    204205    pacNewCodewordBuffer[ uiDesIdx ].ucCWLength = 0;
    205206  }
    206   delete [] m_pacCodewordBuffer;
     207  MEMDELETEARRAY( m_pacCodewordBuffer );
    207208  m_uiNextWriteIdx    = uiNewNextWriteIdx;
    208209  m_uiNextReserveIdx  = uiNewNextReservedIdx;
    209210  m_uiBufferSize      = uiNewBufferSize;
     
    241242{
    242243  for( UInt uiIdx = 0; uiIdx < NUM_V2V_CODERS; uiIdx++ )
    243244  {
    244     m_apcV2VEncoders[ uiIdx ] = new V2VEncoder( uiIdx, m_cCodewordBuffer );
     245    m_apcV2VEncoders[ uiIdx ] = MEMNEW V2VEncoder( uiIdx, m_cCodewordBuffer );
    245246  }
    246247#if PIPE_LOW_DELAY_OPTION
    247248  m_cCodewordBuffer.initDelay( m_apcV2VEncoders, 0 );
     
    252253{
    253254  for( UInt uiIdx = 0; uiIdx < NUM_V2V_CODERS; uiIdx++ )
    254255  {
    255     delete m_apcV2VEncoders[ uiIdx ];
     256    MEMDELETE( m_apcV2VEncoders[ uiIdx ] );
    256257  }
    257258}
    258259
  • source/Lib/TLibEncoder/TEncBinCoderV2VwLB.h

     
    4646#include <cstdlib>
    4747#include <cstring>
    4848
     49#include "../TLibCommon/tool_tracemem.h"
     50
    4951class TEncClearBit : public TEncBinIf {
    5052
    5153public:
     
    132134
    133135public:
    134136    TEncClearBuffer() {
    135         buffer = new parallel_buffer[BUFFER_SIZE];
    136         temp_space = new UChar[TEMP_SIZE];
     137        buffer = MEMNEWARRAY parallel_buffer[BUFFER_SIZE];
     138        temp_space = MEMNEWARRAY UChar[TEMP_SIZE];
    137139        init();
    138140    }
    139141
    140142    virtual ~TEncClearBuffer() {
    141         delete [] temp_space;
    142         delete [] buffer;
     143        MEMDELETEARRAY( temp_space );
     144        MEMDELETEARRAY( buffer );
    143145    }
    144146
    145147    Void setState ( UInt* pui ) { memcpy( m_uiState, pui, sizeof(UInt) * StateCount ); }
     
    173175    virtual void groupStates();
    174176
    175177public:
    176     TEncV2V() { LB_temp_space = new UChar[TEMP_SIZE]; }
    177     ~TEncV2V() { delete [] LB_temp_space; }
     178    TEncV2V() { LB_temp_space = MEMNEWARRAY UChar[TEMP_SIZE]; }
     179    ~TEncV2V() { MEMDELETEARRAY( LB_temp_space ); }
    178180};
    179181
    180182#endif
  • source/Lib/TLibEncoder/TEncCu.cpp

     
    3838#include "TEncCu.h"
    3939#include "TEncAnalyze.h"
    4040
     41#include "../TLibCommon/tool_tracemem.h"
     42
    4143// ====================================================================================================================
    4244// Constructor / destructor / create / destroy
    4345// ====================================================================================================================
     
    5153  Int i;
    5254
    5355  m_uhTotalDepth   = uhTotalDepth + 1;
    54   m_ppcBestCU      = new TComDataCU*[m_uhTotalDepth-1];
    55   m_ppcTempCU      = new TComDataCU*[m_uhTotalDepth-1];
     56  m_ppcBestCU      = MEMNEWARRAY TComDataCU*[m_uhTotalDepth-1];
     57  m_ppcTempCU      = MEMNEWARRAY TComDataCU*[m_uhTotalDepth-1];
    5658
    57   m_ppcPredYuvBest = new TComYuv*[m_uhTotalDepth-1];
    58   m_ppcResiYuvBest = new TComYuv*[m_uhTotalDepth-1];
    59   m_ppcRecoYuvBest = new TComYuv*[m_uhTotalDepth-1];
    60   m_ppcPredYuvTemp = new TComYuv*[m_uhTotalDepth-1];
    61   m_ppcResiYuvTemp = new TComYuv*[m_uhTotalDepth-1];
    62   m_ppcRecoYuvTemp = new TComYuv*[m_uhTotalDepth-1];
    63   m_ppcOrigYuv     = new TComYuv*[m_uhTotalDepth-1];
     59  m_ppcPredYuvBest = MEMNEWARRAY TComYuv*[m_uhTotalDepth-1];
     60  m_ppcResiYuvBest = MEMNEWARRAY TComYuv*[m_uhTotalDepth-1];
     61  m_ppcRecoYuvBest = MEMNEWARRAY TComYuv*[m_uhTotalDepth-1];
     62  m_ppcPredYuvTemp = MEMNEWARRAY TComYuv*[m_uhTotalDepth-1];
     63  m_ppcResiYuvTemp = MEMNEWARRAY TComYuv*[m_uhTotalDepth-1];
     64  m_ppcRecoYuvTemp = MEMNEWARRAY TComYuv*[m_uhTotalDepth-1];
     65  m_ppcOrigYuv     = MEMNEWARRAY TComYuv*[m_uhTotalDepth-1];
    6466
    6567  UInt uiNumPartitions;
    6668  for( i=0 ; i<m_uhTotalDepth-1 ; i++)
     
    6971    UInt uiWidth  = uiMaxWidth  >> i;
    7072    UInt uiHeight = uiMaxHeight >> i;
    7173
    72     m_ppcBestCU[i] = new TComDataCU; m_ppcBestCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false );
    73     m_ppcTempCU[i] = new TComDataCU; m_ppcTempCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false );
     74    m_ppcBestCU[i] = MEMNEW TComDataCU; m_ppcBestCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false );
     75    m_ppcTempCU[i] = MEMNEW TComDataCU; m_ppcTempCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false );
    7476
    75     m_ppcPredYuvBest[i] = new TComYuv; m_ppcPredYuvBest[i]->create(uiWidth, uiHeight);
    76     m_ppcResiYuvBest[i] = new TComYuv; m_ppcResiYuvBest[i]->create(uiWidth, uiHeight);
    77     m_ppcRecoYuvBest[i] = new TComYuv; m_ppcRecoYuvBest[i]->create(uiWidth, uiHeight);
     77    m_ppcPredYuvBest[i] = MEMNEW TComYuv; m_ppcPredYuvBest[i]->create(uiWidth, uiHeight);
     78    m_ppcResiYuvBest[i] = MEMNEW TComYuv; m_ppcResiYuvBest[i]->create(uiWidth, uiHeight);
     79    m_ppcRecoYuvBest[i] = MEMNEW TComYuv; m_ppcRecoYuvBest[i]->create(uiWidth, uiHeight);
    7880
    79     m_ppcPredYuvTemp[i] = new TComYuv; m_ppcPredYuvTemp[i]->create(uiWidth, uiHeight);
    80     m_ppcResiYuvTemp[i] = new TComYuv; m_ppcResiYuvTemp[i]->create(uiWidth, uiHeight);
    81     m_ppcRecoYuvTemp[i] = new TComYuv; m_ppcRecoYuvTemp[i]->create(uiWidth, uiHeight);
     81    m_ppcPredYuvTemp[i] = MEMNEW TComYuv; m_ppcPredYuvTemp[i]->create(uiWidth, uiHeight);
     82    m_ppcResiYuvTemp[i] = MEMNEW TComYuv; m_ppcResiYuvTemp[i]->create(uiWidth, uiHeight);
     83    m_ppcRecoYuvTemp[i] = MEMNEW TComYuv; m_ppcRecoYuvTemp[i]->create(uiWidth, uiHeight);
    8284
    83     m_ppcOrigYuv    [i] = new TComYuv; m_ppcOrigYuv    [i]->create(uiWidth, uiHeight);
     85    m_ppcOrigYuv    [i] = MEMNEW TComYuv; m_ppcOrigYuv    [i]->create(uiWidth, uiHeight);
    8486  }
    8587
    8688  // initialize partition order.
     
    100102  {
    101103    if(m_ppcBestCU[i])
    102104    {
    103       m_ppcBestCU[i]->destroy();      delete m_ppcBestCU[i];      m_ppcBestCU[i] = NULL;
     105      m_ppcBestCU[i]->destroy();      MEMDELETE( m_ppcBestCU[i] );      m_ppcBestCU[i] = NULL;
    104106    }
    105107    if(m_ppcTempCU[i])
    106108    {
    107       m_ppcTempCU[i]->destroy();      delete m_ppcTempCU[i];      m_ppcTempCU[i] = NULL;
     109      m_ppcTempCU[i]->destroy();      MEMDELETE( m_ppcTempCU[i] );      m_ppcTempCU[i] = NULL;
    108110    }
    109111    if(m_ppcPredYuvBest[i])
    110112    {
    111       m_ppcPredYuvBest[i]->destroy(); delete m_ppcPredYuvBest[i]; m_ppcPredYuvBest[i] = NULL;
     113      m_ppcPredYuvBest[i]->destroy(); MEMDELETE( m_ppcPredYuvBest[i] ); m_ppcPredYuvBest[i] = NULL;
    112114    }
    113115    if(m_ppcResiYuvBest[i])
    114116    {
    115       m_ppcResiYuvBest[i]->destroy(); delete m_ppcResiYuvBest[i]; m_ppcResiYuvBest[i] = NULL;
     117      m_ppcResiYuvBest[i]->destroy(); MEMDELETE( m_ppcResiYuvBest[i] ); m_ppcResiYuvBest[i] = NULL;
    116118    }
    117119    if(m_ppcRecoYuvBest[i])
    118120    {
    119       m_ppcRecoYuvBest[i]->destroy(); delete m_ppcRecoYuvBest[i]; m_ppcRecoYuvBest[i] = NULL;
     121      m_ppcRecoYuvBest[i]->destroy(); MEMDELETE( m_ppcRecoYuvBest[i] ); m_ppcRecoYuvBest[i] = NULL;
    120122    }
    121123    if(m_ppcPredYuvTemp[i])
    122124    {
    123       m_ppcPredYuvTemp[i]->destroy(); delete m_ppcPredYuvTemp[i]; m_ppcPredYuvTemp[i] = NULL;
     125      m_ppcPredYuvTemp[i]->destroy(); MEMDELETE( m_ppcPredYuvTemp[i] ); m_ppcPredYuvTemp[i] = NULL;
    124126    }
    125127    if(m_ppcResiYuvTemp[i])
    126128    {
    127       m_ppcResiYuvTemp[i]->destroy(); delete m_ppcResiYuvTemp[i]; m_ppcResiYuvTemp[i] = NULL;
     129      m_ppcResiYuvTemp[i]->destroy(); MEMDELETE( m_ppcResiYuvTemp[i] ); m_ppcResiYuvTemp[i] = NULL;
    128130    }
    129131    if(m_ppcRecoYuvTemp[i])
    130132    {
    131       m_ppcRecoYuvTemp[i]->destroy(); delete m_ppcRecoYuvTemp[i]; m_ppcRecoYuvTemp[i] = NULL;
     133      m_ppcRecoYuvTemp[i]->destroy(); MEMDELETE( m_ppcRecoYuvTemp[i] ); m_ppcRecoYuvTemp[i] = NULL;
    132134    }
    133135    if(m_ppcOrigYuv[i])
    134136    {
    135       m_ppcOrigYuv[i]->destroy();     delete m_ppcOrigYuv[i];     m_ppcOrigYuv[i] = NULL;
     137      m_ppcOrigYuv[i]->destroy();     MEMDELETE( m_ppcOrigYuv[i] );     m_ppcOrigYuv[i] = NULL;
    136138    }
    137139  }
    138140  if(m_ppcBestCU)
    139141  {
    140     delete [] m_ppcBestCU;
     142    MEMDELETEARRAY( m_ppcBestCU );
    141143    m_ppcBestCU = NULL;
    142144  }
    143145  if(m_ppcTempCU)
    144146  {
    145     delete [] m_ppcTempCU;
     147    MEMDELETEARRAY( m_ppcTempCU );
    146148    m_ppcTempCU = NULL;
    147149  }
    148150
    149151  if(m_ppcPredYuvBest)
    150152  {
    151     delete [] m_ppcPredYuvBest;
     153    MEMDELETEARRAY( m_ppcPredYuvBest );
    152154    m_ppcPredYuvBest = NULL;
    153155  }
    154156  if(m_ppcResiYuvBest)
    155157  {
    156     delete [] m_ppcResiYuvBest;
     158    MEMDELETEARRAY( m_ppcResiYuvBest );
    157159    m_ppcResiYuvBest = NULL;
    158160  }
    159161  if(m_ppcRecoYuvBest)
    160162  {
    161     delete [] m_ppcRecoYuvBest;
     163    MEMDELETEARRAY( m_ppcRecoYuvBest );
    162164    m_ppcRecoYuvBest = NULL;
    163165  }
    164166  if(m_ppcPredYuvTemp)
    165167  {
    166     delete [] m_ppcPredYuvTemp;
     168    MEMDELETEARRAY( m_ppcPredYuvTemp );
    167169    m_ppcPredYuvTemp = NULL;
    168170  }
    169171  if(m_ppcResiYuvTemp)
    170172  {
    171     delete [] m_ppcResiYuvTemp;
     173    MEMDELETEARRAY( m_ppcResiYuvTemp );
    172174    m_ppcResiYuvTemp = NULL;
    173175  }
    174176  if(m_ppcRecoYuvTemp)
    175177  {
    176     delete [] m_ppcRecoYuvTemp;
     178    MEMDELETEARRAY( m_ppcRecoYuvTemp );
    177179    m_ppcRecoYuvTemp = NULL;
    178180  }
    179181  if(m_ppcOrigYuv)
    180182  {
    181     delete [] m_ppcOrigYuv;
     183    MEMDELETEARRAY( m_ppcOrigYuv );
    182184    m_ppcOrigYuv = NULL;
    183185  }
    184186}
  • source/Lib/TLibEncoder/TEncGOP.cpp

     
    3939
    4040#include <time.h>
    4141
     42#include "../TLibCommon/tool_tracemem.h"
     43
    4244// ====================================================================================================================
    4345// Constructor / destructor / initialization / destroy
    4446// ====================================================================================================================
     
    123125  TComPicYuv      cPicOrg;
    124126  TComPic*        pcOrgRefList[2][MAX_REF_PIC_NUM];
    125127//stats
    126   TComBitstream*  pcOut = new TComBitstream;
     128  TComBitstream*  pcOut = MEMNEW TComBitstream;
    127129  pcOut->create( 500000 );
    128130
    129131  xInitGOP( iPOCLast, iNumPicRcvd, rcListPic, rcListPicYuvRecOut );
     
    573575  }
    574576
    575577  pcOut->destroy();
    576   delete pcOut;
     578  MEMDELETE( pcOut );
    577579
    578580  assert ( m_iNumPicCoded == iNumPicRcvd );
    579581}
     
    993995    uibits );
    994996  printf( "[Y %6.4lf dB    U %6.4lf dB    V %6.4lf dB]  ", dYPSNR, dUPSNR, dVPSNR );
    995997  printf ("[ET %5.0f ] ", dEncTime );
     998  printf( "[MA %.1lf MB, %.1lf KTimes] " , GetMaxMBMemAllocated() , GetTimesMemAllocation() / 1000 );
    996999
    9971000  for (Int iRefList = 0; iRefList < 2; iRefList++)
    9981001  {
  • source/Lib/TLibEncoder/TEncSearch.cpp

     
    3737#include "../TLibCommon/TComMotionInfo.h"
    3838#include "TEncSearch.h"
    3939
     40#include "../TLibCommon/tool_tracemem.h"
     41
     42
    4043#ifdef ROUNDING_CONTROL_BIPRED
    4144__inline Pel  xClip  (Pel x )      { return ( (x < 0) ? 0 : (x > (Pel)g_uiIBDI_MAX) ? (Pel)g_uiIBDI_MAX : x ); }
    4245#endif
     
    119122{
    120123  if ( m_pTempPel )
    121124  {
    122     delete [] m_pTempPel;
     125    MEMDELETEARRAY( m_pTempPel );
    123126    m_pTempPel = NULL;
    124127  }
    125128#if HHI_RQT
     
    128131    const UInt uiNumLayersAllocated = m_pcEncCfg->getQuadtreeTULog2MaxSize()-m_pcEncCfg->getQuadtreeTULog2MinSize()+1;
    129132    for( UInt ui = 0; ui < uiNumLayersAllocated; ++ui )
    130133    {
    131       delete[] m_ppcQTTempCoeffY[ui];
    132       delete[] m_ppcQTTempCoeffCb[ui];
    133       delete[] m_ppcQTTempCoeffCr[ui];
     134      MEMDELETEARRAY( m_ppcQTTempCoeffY[ui] );
     135      MEMDELETEARRAY( m_ppcQTTempCoeffCb[ui] );
     136      MEMDELETEARRAY( m_ppcQTTempCoeffCr[ui] );
    134137      m_pcQTTempTComYuv[ui].destroy();
    135138    }
    136     delete[] m_ppcQTTempCoeffY;
    137     delete[] m_ppcQTTempCoeffCb;
    138     delete[] m_ppcQTTempCoeffCr;
    139     delete[] m_pcQTTempCoeffY;
    140     delete[] m_pcQTTempCoeffCb;
    141     delete[] m_pcQTTempCoeffCr;
    142     delete[] m_puhQTTempTrIdx;
    143     delete[] m_puhQTTempCbf[0];
    144     delete[] m_puhQTTempCbf[1];
    145     delete[] m_puhQTTempCbf[2];
    146     delete[] m_pcQTTempTComYuv;
     139    MEMDELETEARRAY( m_ppcQTTempCoeffY );
     140    MEMDELETEARRAY( m_ppcQTTempCoeffCb );
     141    MEMDELETEARRAY( m_ppcQTTempCoeffCr );
     142    MEMDELETEARRAY( m_pcQTTempCoeffY );
     143    MEMDELETEARRAY( m_pcQTTempCoeffCb );
     144    MEMDELETEARRAY( m_pcQTTempCoeffCr );
     145    MEMDELETEARRAY( m_puhQTTempTrIdx );
     146    MEMDELETEARRAY( m_puhQTTempCbf[0] );
     147    MEMDELETEARRAY( m_puhQTTempCbf[1] );
     148    MEMDELETEARRAY( m_puhQTTempCbf[2] );
     149    MEMDELETEARRAY( m_pcQTTempTComYuv );
    147150  }
    148151#endif
    149152}
     
    194197 
    195198  initTempBuff();
    196199 
    197   m_pTempPel = new Pel[g_uiMaxCUWidth*g_uiMaxCUHeight];
     200  m_pTempPel = MEMNEWARRAY Pel[g_uiMaxCUWidth*g_uiMaxCUHeight];
    198201 
    199202  m_iDIFTap2 = (m_iDIFTap << 1);
    200203 
     
    202205  if( pcEncCfg->getQuadtreeTUFlag() )
    203206  {
    204207    const UInt uiNumLayersToAllocate = pcEncCfg->getQuadtreeTULog2MaxSize()-pcEncCfg->getQuadtreeTULog2MinSize()+1;
    205     m_ppcQTTempCoeffY  = new TCoeff*[uiNumLayersToAllocate];
    206     m_ppcQTTempCoeffCb = new TCoeff*[uiNumLayersToAllocate];
    207     m_ppcQTTempCoeffCr = new TCoeff*[uiNumLayersToAllocate];
    208     m_pcQTTempCoeffY   = new TCoeff [g_uiMaxCUWidth*g_uiMaxCUHeight   ];
    209     m_pcQTTempCoeffCb  = new TCoeff [g_uiMaxCUWidth*g_uiMaxCUHeight>>2];
    210     m_pcQTTempCoeffCr  = new TCoeff [g_uiMaxCUWidth*g_uiMaxCUHeight>>2];
     208    m_ppcQTTempCoeffY  = MEMNEWARRAY TCoeff*[uiNumLayersToAllocate];
     209    m_ppcQTTempCoeffCb = MEMNEWARRAY TCoeff*[uiNumLayersToAllocate];
     210    m_ppcQTTempCoeffCr = MEMNEWARRAY TCoeff*[uiNumLayersToAllocate];
     211    m_pcQTTempCoeffY   = MEMNEWARRAY TCoeff [g_uiMaxCUWidth*g_uiMaxCUHeight   ];
     212    m_pcQTTempCoeffCb  = MEMNEWARRAY TCoeff [g_uiMaxCUWidth*g_uiMaxCUHeight>>2];
     213    m_pcQTTempCoeffCr  = MEMNEWARRAY TCoeff [g_uiMaxCUWidth*g_uiMaxCUHeight>>2];
    211214   
    212215    const UInt uiNumPartitions = 1<<(g_uiMaxCUDepth<<1);
    213     m_puhQTTempTrIdx   = new UChar  [uiNumPartitions];
    214     m_puhQTTempCbf[0]  = new UChar  [uiNumPartitions];
    215     m_puhQTTempCbf[1]  = new UChar  [uiNumPartitions];
    216     m_puhQTTempCbf[2]  = new UChar  [uiNumPartitions];
    217     m_pcQTTempTComYuv  = new TComYuv[uiNumLayersToAllocate];
     216    m_puhQTTempTrIdx   = MEMNEWARRAY UChar  [uiNumPartitions];
     217    m_puhQTTempCbf[0]  = MEMNEWARRAY UChar  [uiNumPartitions];
     218    m_puhQTTempCbf[1]  = MEMNEWARRAY UChar  [uiNumPartitions];
     219    m_puhQTTempCbf[2]  = MEMNEWARRAY UChar  [uiNumPartitions];
     220    m_pcQTTempTComYuv  = MEMNEWARRAY TComYuv[uiNumLayersToAllocate];
    218221    for( UInt ui = 0; ui < uiNumLayersToAllocate; ++ui )
    219222    {
    220       m_ppcQTTempCoeffY[ui]  = new TCoeff[g_uiMaxCUWidth*g_uiMaxCUHeight   ];
    221       m_ppcQTTempCoeffCb[ui] = new TCoeff[g_uiMaxCUWidth*g_uiMaxCUHeight>>2];
    222       m_ppcQTTempCoeffCr[ui] = new TCoeff[g_uiMaxCUWidth*g_uiMaxCUHeight>>2];
     223      m_ppcQTTempCoeffY[ui]  = MEMNEWARRAY TCoeff[g_uiMaxCUWidth*g_uiMaxCUHeight   ];
     224      m_ppcQTTempCoeffCb[ui] = MEMNEWARRAY TCoeff[g_uiMaxCUWidth*g_uiMaxCUHeight>>2];
     225      m_ppcQTTempCoeffCr[ui] = MEMNEWARRAY TCoeff[g_uiMaxCUWidth*g_uiMaxCUHeight>>2];
    223226      m_pcQTTempTComYuv[ui].create( g_uiMaxCUWidth, g_uiMaxCUHeight );
    224227    }
    225228  }
  • source/Lib/TLibEncoder/TEncSlice.cpp

     
    3636#include "TEncTop.h"
    3737#include "TEncSlice.h"
    3838
     39#include "../TLibCommon/tool_tracemem.h"
     40
    3941// ====================================================================================================================
    4042// Constructor / destructor / create / destroy
    4143// ====================================================================================================================
     
    6668  // create prediction picture
    6769  if ( m_apcPicYuvPred == NULL )
    6870  {
    69     m_apcPicYuvPred  = new TComPicYuv;
     71    m_apcPicYuvPred  = MEMNEW TComPicYuv;
    7072    m_apcPicYuvPred->create( iWidth, iHeight, iMaxCUWidth, iMaxCUHeight, uhTotalDepth );
    7173  }
    7274
    7375  // create residual picture
    7476  if( m_apcPicYuvResi == NULL )
    7577  {
    76     m_apcPicYuvResi  = new TComPicYuv;
     78    m_apcPicYuvResi  = MEMNEW TComPicYuv;
    7779    m_apcPicYuvResi->create( iWidth, iHeight, iMaxCUWidth, iMaxCUHeight, uhTotalDepth );
    7880  }
    7981}
     
    8486  if ( m_apcPicYuvPred )
    8587  {
    8688    m_apcPicYuvPred->destroy();
    87     delete m_apcPicYuvPred;
     89    MEMDELETE( m_apcPicYuvPred );
    8890    m_apcPicYuvPred  = NULL;
    8991  }
    9092
     
    9294  if ( m_apcPicYuvResi )
    9395  {
    9496    m_apcPicYuvResi->destroy();
    95     delete m_apcPicYuvResi;
     97    MEMDELETE( m_apcPicYuvResi );
    9698    m_apcPicYuvResi  = NULL;
    9799  }
    98100
     
    103105    if(m_apcVirtPic[j][i])
    104106    {
    105107      m_apcVirtPic[j][i]->destroy();
    106       delete m_apcVirtPic[j][i];
     108      MEMDELETE( m_apcVirtPic[j][i] );
    107109      m_apcVirtPic[j][i]=NULL;
    108110    }
    109111  }
     
    158160    {
    159161      if ( m_apcVirtPic[j][i] == NULL)
    160162      {
    161         m_apcVirtPic[j][i] = new TComPic;
     163        m_apcVirtPic[j][i] = MEMNEW TComPic;
    162164        m_apcVirtPic[j][i]->create( iWidth, iHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true );
    163165      }
    164166    }
  • source/Lib/TLibEncoder/TEncTop.cpp

     
    3636#include "../TLibCommon/CommonDef.h"
    3737#include "TEncTop.h"
    3838
     39#include "../TLibCommon/tool_tracemem.h"
     40
    3941// ====================================================================================================================
    4042// Constructor / destructor / create / destroy
    4143// ====================================================================================================================
     
    8385  // if SBAC-based RD optimization is used
    8486  if( m_bUseSBACRD )
    8587  {
    86     m_pppcRDSbacCoder = new TEncSbac** [g_uiMaxCUDepth+1];
    87     m_pppcBinCoderCABAC = new TEncBinCABAC** [g_uiMaxCUDepth+1];
     88    m_pppcRDSbacCoder = MEMNEWARRAY TEncSbac** [g_uiMaxCUDepth+1];
     89    m_pppcBinCoderCABAC = MEMNEWARRAY TEncBinCABAC** [g_uiMaxCUDepth+1];
    8890
    8991    for ( Int iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
    9092    {
    91       m_pppcRDSbacCoder[iDepth] = new TEncSbac* [CI_NUM];
    92       m_pppcBinCoderCABAC[iDepth] = new TEncBinCABAC* [CI_NUM];
     93      m_pppcRDSbacCoder[iDepth] = MEMNEWARRAY TEncSbac* [CI_NUM];
     94      m_pppcBinCoderCABAC[iDepth] = MEMNEWARRAY TEncBinCABAC* [CI_NUM];
    9395
    9496      for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
    9597      {
    96         m_pppcRDSbacCoder[iDepth][iCIIdx] = new TEncSbac;
    97         m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABAC;
     98        m_pppcRDSbacCoder[iDepth][iCIIdx] = MEMNEW TEncSbac;
     99        m_pppcBinCoderCABAC [iDepth][iCIIdx] = MEMNEW TEncBinCABAC;
    98100        m_pppcRDSbacCoder   [iDepth][iCIIdx]->init( m_pppcBinCoderCABAC [iDepth][iCIIdx] );
    99101      }
    100102    }
     
    120122    {
    121123      for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
    122124      {
    123         delete m_pppcRDSbacCoder[iDepth][iCIIdx];
    124         delete m_pppcBinCoderCABAC[iDepth][iCIIdx];
     125        MEMDELETE( m_pppcRDSbacCoder[iDepth][iCIIdx] );
     126        MEMDELETE( m_pppcBinCoderCABAC[iDepth][iCIIdx] );
    125127      }
    126128    }
    127129
    128130    for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
    129131    {
    130       delete [] m_pppcRDSbacCoder[iDepth];
    131       delete [] m_pppcBinCoderCABAC[iDepth];
     132      MEMDELETEARRAY( m_pppcRDSbacCoder[iDepth] );
     133      MEMDELETEARRAY( m_pppcBinCoderCABAC[iDepth] );
    132134    }
    133135
    134     delete [] m_pppcRDSbacCoder;
    135     delete [] m_pppcBinCoderCABAC;
     136    MEMDELETEARRAY( m_pppcRDSbacCoder );
     137    MEMDELETEARRAY( m_pppcBinCoderCABAC );
    136138  }
    137139
    138140  // destroy ROM
     
    188190    TComPic* pcPic = *(iterPic++);
    189191
    190192    pcPic->destroy();
    191     delete pcPic;
     193    MEMDELETE( pcPic );
    192194    pcPic = NULL;
    193195  }
    194196}
     
    260262      rpcPic = *(++iterPic);
    261263      if ( abs(rpcPic->getPOC() - m_iPOCLast) <= m_iGOPSize )
    262264      {
    263         rpcPic = new TComPic;
     265        rpcPic = MEMNEW TComPic;
    264266        rpcPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
    265267      }
    266268      else
     
    272274  }
    273275  else
    274276  {
    275     rpcPic = new TComPic;
     277    rpcPic = MEMNEW TComPic;
    276278    rpcPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
    277279  }
    278280
  • source/Lib/TLibVideoIO/TVideoIOYuv.cpp

     
    4242
    4343#include "TVideoIOYuv.h"
    4444
     45#include "../TLibCommon/tool_tracemem.h"
     46
    4547using namespace std;
    4648
    4749// ====================================================================================================================
     
    104106  iHeight = rpcPicYuv->getHeight() - aiPad[1];
    105107
    106108  // allocate 8-bit buffer
    107   Pxl*  apuchBuf = new Pxl[iWidth];
     109  Pxl*  apuchBuf = MEMNEWARRAY Pxl[iWidth];
    108110
    109111  // Y
    110112  Pel*  pDst = rpcPicYuv->getLumaAddr();
     
    167169    pDst += iStride;
    168170  }
    169171
    170   delete [] apuchBuf;
     172  MEMDELETEARRAY( apuchBuf );
    171173
    172174  return;
    173175}
     
    185187  Int   iStride = pcPicYuv->getStride();
    186188
    187189  // allocate 8-bit buffer
    188   Pxl*  apuchBuf = new Pxl[iWidth];
     190  Pxl*  apuchBuf = MEMNEWARRAY Pxl[iWidth];
    189191
    190192  //  Y
    191193  Pel*  pSrc = pcPicYuv->getLumaAddr();
     
    218220    pSrc += iStride;
    219221  }
    220222
    221   delete [] apuchBuf;
     223  MEMDELETEARRAY( apuchBuf );
    222224}
    223225