[Theora] Less memory allocations

Anton Yudintsev anton at gaijin.ru
Wed Jan 11 16:04:49 PST 2006


Hi.

We use theora in games and find out that although PostProcessingLevel
is off by default, theora allocates memory for postprocessing in any
case.
The code below differs from original alpha5 only by adding in certain
places
 "... pbi->PostProcessingLevel == 0 ? 0 : ..."
 It is working and allocate less memory.
May be it is good idea to add this (or gather all
 preprocess things in one if(), for example) in future releases.
 
void InitFragmentInfo(PB_INSTANCE * pbi){
  /* clear any existing info */
  ClearFragmentInfo(pbi);

  /* Perform Fragment Allocations */
  pbi->display_fragments =
    _ogg_malloc(pbi->UnitFragments * sizeof(*pbi->display_fragments));

  pbi->pixel_index_table =
    _ogg_malloc(pbi->UnitFragments * sizeof(*pbi->pixel_index_table));

  pbi->recon_pixel_index_table =
    _ogg_malloc(pbi->UnitFragments * sizeof(*pbi->recon_pixel_index_table));
 
  pbi->FragTokenCounts =
    pbi->PostProcessingLevel == 0 ? 0 : _ogg_malloc(pbi->UnitFragments * sizeof(*pbi->FragTokenCounts));

  pbi->CodedBlockList =
    _ogg_malloc(pbi->UnitFragments * sizeof(*pbi->CodedBlockList));

  pbi->FragMVect =
    _ogg_malloc(pbi->UnitFragments * sizeof(*pbi->FragMVect));

  pbi->FragCoeffs =
    _ogg_malloc(pbi->UnitFragments * sizeof(*pbi->FragCoeffs));

  pbi->FragCoefEOB =
    _ogg_malloc(pbi->UnitFragments * sizeof(*pbi->FragCoefEOB));

  pbi->skipped_display_fragments =
    _ogg_malloc(pbi->UnitFragments * sizeof(*pbi->skipped_display_fragments));

  pbi->QFragData =
    _ogg_malloc(pbi->UnitFragments * sizeof(*pbi->QFragData));

  pbi->TokenList =
    pbi->PostProcessingLevel == 0 ? 0 : _ogg_malloc(pbi->UnitFragments * sizeof(*pbi->TokenList));

  pbi->FragCodingMethod =
    _ogg_malloc(pbi->UnitFragments * sizeof(*pbi->FragCodingMethod));

  pbi->FragCoordinates =
    _ogg_malloc(pbi->UnitFragments * sizeof(*pbi->FragCoordinates));

  pbi->FragQIndex =
    pbi->PostProcessingLevel == 0 ? 0 : _ogg_malloc(pbi->UnitFragments * sizeof(*pbi->FragQIndex));

  pbi->PPCoefBuffer =
    pbi->PostProcessingLevel == 0 ? 0 : _ogg_malloc(pbi->UnitFragments * sizeof(*pbi->PPCoefBuffer));

  pbi->FragmentVariances =
    pbi->PostProcessingLevel == 0 ? 0 : _ogg_malloc(pbi->UnitFragments * sizeof(*pbi->FragmentVariances));

  pbi->_Nodes =
    pbi->PostProcessingLevel == 0 ? 0 : _ogg_malloc(pbi->UnitFragments * sizeof(*pbi->_Nodes));

  /* Super Block Initialization */
  pbi->SBCodedFlags =
    _ogg_malloc(pbi->SuperBlocks * sizeof(*pbi->SBCodedFlags));

  pbi->SBFullyFlags =
    _ogg_malloc(pbi->SuperBlocks * sizeof(*pbi->SBFullyFlags));

  /* Macro Block Initialization */
  pbi->MBCodedFlags =
    _ogg_malloc(pbi->MacroBlocks * sizeof(*pbi->MBCodedFlags));

  pbi->MBFullyFlags =
    pbi->PostProcessingLevel == 0 ? 0 : _ogg_malloc(pbi->MacroBlocks * sizeof(*pbi->MBFullyFlags));

  pbi->BlockMap =
    _ogg_malloc(pbi->SuperBlocks * sizeof(*pbi->BlockMap));

}
void InitFrameInfo(PB_INSTANCE * pbi, unsigned int FrameSize){

  /* clear any existing info */
  ClearFrameInfo(pbi);

  /* allocate frames */
  pbi->ThisFrameRecon =
    _ogg_malloc(FrameSize*sizeof(*pbi->ThisFrameRecon));

  pbi->GoldenFrame =
    _ogg_malloc(FrameSize*sizeof(*pbi->GoldenFrame));

  pbi->LastFrameRecon =
    _ogg_malloc(FrameSize*sizeof(*pbi->LastFrameRecon));

  pbi->PostProcessBuffer =
    pbi->PostProcessingLevel == 0 ? 0 : _ogg_malloc(FrameSize*sizeof(*pbi->PostProcessBuffer));
}



Best regards,
  Yudintsev Anton.





More information about the Theora mailing list