Home > Back-end > How to solve the Range check error error
How to solve the Range check error error
Time:09-30
Procedure TForm1. Btn1Click (Sender: TObject); Var I: int64; X: an array of int64; IntS: int64; The begin I:=1000000000; Setlength (x, I);//an error here IntS:=gettickcount; Randomize. I:=0; While i<=high (x) do The begin [I] : x=the random (high (x) + 1); I:=I + 1; end; IntS:=gettickcount - intS; Lbl1. Caption:='takes' + inttostr (ints) +' ms'; end;
CodePudding user response:
1 g Int64, that is, at least 8 gb of memory is enough. If you are a 32-bit operating system operating system for each process at least memory only 2 g or 3 g (opened PAE mode) If it is a 64 - bit system, you didn't so much the physical memory.
Setlength reported Range mainly because of wrong and you here beyond the size of the dynamic array, a 32-bit system dynamic array is at most 2 g memory
NeededSize:=newLength * elSize;//a 32-bit system under neededSize is a 32-bit integer, you this is beyond the maximum number, becomes negative. Behind that would throw exceptions. If neededSize div newLength & lt;> ElSize then Error (reRangeError);