Frage zu MeasureCharacterRange bzw. new und delete



  • Hallo,

    ich habe eine Verständnisfrage zu folgendem Beispiel auf der Seite:

    http://msdn.microsoft.com/en-us/library/ms535796(v=VS.85).aspx

    VOID MeasureCharRanges(HDC hdc)
    {
       Graphics graphics(hdc);
    
       // Brushes and pens used for drawing and painting
       SolidBrush blueBrush(Color(255, 0, 0, 255));
       SolidBrush redBrush(Color(100, 255, 0, 0));
       Pen        blackPen(Color(255, 0, 0, 0));
    
       // Layout rectangles used for drawing strings
       RectF   layoutRect_A(20.0f, 20.0f, 130.0f, 130.0f);
       RectF   layoutRect_B(160.0f, 20.0f, 165.0f, 130.0f);
       RectF   layoutRect_C(335.0f, 20.0f, 165.0f, 130.0f);
    
       // Three different ranges of character positions within the string
       CharacterRange charRanges[3] = { CharacterRange(3, 5),
                                        CharacterRange(15, 2),
                                        CharacterRange(30, 15), };
    
       // Font and string format to apply to string when drawing
       Font         myFont(L"Times New Roman", 16.0f);
       StringFormat strFormat;
    
        // Other variables
       Region* pCharRangeRegions; // pointer to CharacterRange regions
       short   i;                 // loop counter
       INT     count;             // number of character ranges set
       WCHAR   string[] = L"The quick, brown fox easily jumps over the lazy dog.";
    
       // Set three ranges of character positions.
       strFormat.SetMeasurableCharacterRanges(3, charRanges);
    
       // Get the number of ranges that have been set, and allocate memory to 
       // store the regions that correspond to the ranges.
       count = strFormat.GetMeasurableCharacterRangeCount();
       pCharRangeRegions = new Region[count];
    
       // Get the regions that correspond to the ranges within the string when
       // layout rectangle A is used. Then draw the string, and show the regions.
       graphics.MeasureCharacterRanges(string, -1,
          &myFont, layoutRect_A, &strFormat, count, pCharRangeRegions);
       graphics.DrawString(string, -1,
          &myFont, layoutRect_A, &strFormat, &blueBrush);
       graphics.DrawRectangle(&blackPen, layoutRect_A);
       for ( i = 0; i < count; i++)
       {
          graphics.FillRegion(&redBrush, pCharRangeRegions + i);
       }
    
       // Get the regions that correspond to the ranges within the string when
       // layout rectangle B is used. Then draw the string, and show the regions.
       graphics.MeasureCharacterRanges(string, -1,
          &myFont, layoutRect_B, &strFormat, count, pCharRangeRegions);
       graphics.DrawString(string, -1,
          &myFont, layoutRect_B, &strFormat, &blueBrush);
       graphics.DrawRectangle(&blackPen, layoutRect_B);
       for ( i = 0; i < count; i++)
       {
          graphics.FillRegion(&redBrush, pCharRangeRegions + i);
       }
    
       // Get the regions that correspond to the ranges within the string when
       // layout rectangle C is used. Set trailing spaces to be included in the
       // regions. Then draw the string, and show the regions.
       strFormat.SetFormatFlags(StringFormatFlagsMeasureTrailingSpaces);
       graphics.MeasureCharacterRanges(string, -1,
          &myFont, layoutRect_C, &strFormat, count, pCharRangeRegions);
       graphics.DrawString(string, -1,
          &myFont, layoutRect_C, &strFormat, &blueBrush);
       graphics.DrawRectangle(&blackPen, layoutRect_C);
       for ( i = 0; i < count; i++)
       {
          graphics.FillRegion(&redBrush, pCharRangeRegions + i);
       }
    }
    

    Frage:

    Was ist mit der Zeile:

    pCharRangeRegions = new Region[count];
    

    Warum wird in dem Beispiel kein "delete" am Ende aufgerufen? Hat das einen Grund?


  • Mod

    Für mich fehlt ein delete []. IMHO ein Bug und Leak.


Anmelden zum Antworten