Ada 95 Quality and Style Guide Chapter 10

Chapter 10: Improving Performance - TOC - 10.4 DATA STRUCTURES

10.4.3 Unconstrained Records

guideline

  • Use fixed-size components for records when measured performance indicates.

  • example

    subtype Line_Range   is Integer range 0 .. Max_Lines;
    subtype Length_Range is Integer range 0 .. Max_Length;
    
    -- Note that Max_Lines and Max_Length need to be static
    type Paragraph_Body is array (Line_Range range <>, Length_Range range <>) of Character;
    
    type Paragraph (Lines : Line_Range := 0; Line_Length : Length_Range := 0) is
       record
          Text : Paragraph_Body (1 .. Lines, 1 .. Line_Length);
       end record;
    
    

    rationale

    Determine the size and speed impact of unconstrained records having components depending on discriminants. Some compilers will allocate the maximum possible size to each object of the type; others will use pointers to the dependent components, incurring a possible heap performance penalty. Consider the possibility of using fixed-size components.


    < Previous Page Search Contents Index Next Page >
    1 2 3 4 5 6 7 8 9 10 11
    TOC TOC TOC TOC TOC TOC TOC TOC TOC TOC TOC
    Appendix References Bibliography