var
   i,j,k,l,m,n,o:integer;
   MyInt:array[0..9,0..9,0..9,0..9,0..9,0..9,0..9] of string;
   str:string;
begin
   //生成1000万个不重复的7位数字
   for i := 0 to 9 do //第一位的数字
   begin
       for j := 0 to 9 do
       begin
          for k := 0 to 9 do
          begin
             for l :=0 to 9 do
             begin
                for m := 0 to 9 do
                begin
                   for n := 0 to 9 do
                   begin
                      for o := 0 to 9 do
                      begin
                         str:= inttostr(i)+inttostr(j)+inttostr(k)+inttostr(l)+inttostr(m)+inttostr(n)+inttostr(o);
                         MyInt[i,j,k,l,m,n,o]:= str;
                      end;
                   end;
                end;
             end;
          end;
       end;
   end;      
end;上述代码在运行中创建变量MyInt:array[0..9,0..9,0..9,0..9,0..9,0..9,0..9] of string;
时报内存溢出,请教各位高手,怎么解决这样的问题,或有其它的解决办法。

解决方案 »

  1.   

    用动态数组呢?
    var
      MyInt:array of array of array of array of array of array of array of string;SetLength(MyInt,10,10,10,10,10,10,10);
      

  2.   

    var
      iIndex: Integer;
      list: TStringList;
    begin
      for iIndex:=0 to 10000000 do
      begin
        list.AddString(IntToStr(iIndex));
      end;
    end;
      

  3.   

    可以用{$MINSTACKSIZE number}  设置delphi 6 帮助
    变量 全局变量在应用程序的数据段(data segment)中分配并且在程序执行的全过程中一直存在。局部变量(声明在过程和函数中的变量)驻留在应用程序的栈(stack)中。每次过程或函数被调用时,将分配一套局部变量;过程或函数退出时,局部殡殓被释放。编译器优化可能除去早先的变量。注意:  在Linux中,栈的尺寸仅由环境设置。在Windows中,应用程序的栈通过两个值被定义:最小栈尺寸(minimum stack size)和最大栈尺寸(maximum stack size)。这两个值通过编译指示$MINSTACKSIZE和$MAXSTACKSIZE被控制,缺省值分别是16,384字节(16KB)和1,048,576字节(1MB)。应确保应用程序的最小栈尺寸是可用的,并且应用程序栈的增长不允许超过最大栈尺寸。如果没有足够的可以内存来满足应用程序的最小栈请求,Windows将在试图启动应用程序时报告一个错误。如果一个Windows应用程序请求的栈空间多于最小栈空间指定的值,那么额外的内存会以4K为增量自动被分配。如果分配额外栈空间失败,那么不是因为多于的内存不可用,就是因为栈的总尺寸超出了既定的最大栈尺寸,这时将引发EStackOverflow异常。(栈溢出检查是自动完成的。$S编译指示最初用来控制栈溢出检查,现在仅维持向后兼容。)在Windows或Linux中,用过程GetMem或New创建的动态变量是在堆(heap)中分配的,并且一直存在直到被FreeMem或Dispose释放。长串(long strings)、宽串(wide strings)、动态数组(dynamic arrays)、变体(variants)以及接口(interfaces)等都是堆分配的(heap-allocated),但它们的内存都是被自动管理的。Memory allocation sizes (Delphi)
     Type 
     Parameter 
    Syntax 
     {$M minstacksize,maxstacksize} {$MINSTACKSIZE number} {$MAXSTACKSIZE number} 
    Default 
     {$M 16384,1048576}
    Scope 
     Global Res 
    The $MINSTACKSIZE and $MAXSTACKSIZE directives are used in Win32 programming only. 
    The $M directive specifies an application's stack allocation parameters. minstacksize must be an integer number between 1024 and 2147483647 that specifies the minimum size of an application's stack, and maxstacksize must be an integer number between minstacksize and 2147483647 that specifies the maximum size of an application's stack.
     
    If there is not enough memory available to satisfy an application's minimum stack requirement, Windows will report an error upon attempting to start the application.
     
    An application's stack is never allowed to grow larger than the maximum stack size. Any attempt to grow the stack beyond the maximum stack size causes an EStackOverflow exception to be raised.
     
    The $MINSTACKSIZE and $MAXSTACKSIZE directives allow the minimum and maximum stack sizes to be specified separately. 
    The memory allocation directives are meaningful only in a program. They should not be used in a library or a unit.