optimize memory usage (and performance)

    • Offizieller Beitrag

    WPTools 5 usually consumes less memory than version 4 - but the memory usage is much more dynamic, this means the more text features you use the more memory will be required.

    A simple test:

    Code
    var i: Integer;    tim : Cardinal;begin  ShowMessage('Start');  tim := GetTickCount;  WPRichText1.Clear;  for i := 0 to 20000 do // twenty thousand lines  begin    WPRichText1.InputString('1234567890123456789012345678901234567890123456789012345678901234567890');    WPRichText1.InputString(#13);  end;  WPRichText1.ReformatAll(true);  ShowMessage(Format('%d pages in %d mms', [WPRichText1.CountPages,GetTickCount-tim]));end;

    On this system (Pentium M, 1.6Ghz) this runs through in about 40 seconds, creates 801 pages and consumes 47,5 MB. It adds 1200000 characters in 20000 paragraphs.

    Please note that the above uses the standard 'InputString' method - fully covered by the undo buffer.

    You can improve the performance with just one line

    WPRichText1.EditOptions := WPRichText1.EditOptions - [wpActivateUndo];

    Now it runs through in just 0.8 sec and requires 27.5 MB RAM.

    A different, optimized approach is

    Here it is important that the previous paragraph (oldpar) is stored and reused. The procedure 'AppendPar' always searches for the last paragraph which can be time consuming.

    The above code runs through in 0,57 sec. You see that the version with 'InputString' is not much slower - if undo has been disabled.

    Julian Ziersch