title: Delphi 7, strings problems
body: <p>In my project I have a problem with strings "out of memory exception", MM is not used. The problem shows when lengths of the string goes to 2 300,000 symbols. Despite the fact that there is enough memory and in the same part of code I can create a sting with 100,000,000 characters.</p>
  
  <p>Google did not help, I can't disassemble it (have no skills), so I decided to create a minimal test example, where I can get out of memory exception on string less then 2 000 000 000 symbols. I could not create such example, but I created something stranger:</p>
  
  <pre><code>program Project2;
  {$APPTYPE CONSOLE}
  uses
     SysUtils;
  
  var s : string;
      k : integer;
  
  function b : string;
  begin
   result := 'f';
  end;
  
  procedure c;
  var ss : string;
  begin
    s := s + '{' +  b + '}';
    ss :=  'a';
  
    if k mod 100001 = 0 then
    begin
       // ss[1] := 'd';    // uncoment me
       write(k mod 10);
    end;
  
    inc(k);
  end;
  
  begin
    while true do c;
  end.
  </code></pre>
  
  <p>This code works fine. It just adds something to a global string with some extra operations. The thing is if  you uncomment marked string it will slow down significantly (with or without optimization). Considering that this assign value once in 100,001 iterations, it must not slow down.</p>
  
  <p>Questions:</p>
  
  <ol>
  <li><p>How do default strings in Delphi work?</p></li>
  <li><p>How to avoid slow down?</p></li>
  <li><p>How to avoid out of memory?</p></li>
  </ol>
  
  <p>P.S. If I include FastMM into the main project the error disappears 
  p.p.s The example with the string uncommented sends my Windows 7 to BSOD in 3 minutes (from user mode).</p>