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);

CodePudding user response:

Setlength (x, I); I as an Integer

CodePudding user response:

reference 1st floor wr960204 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);


X: an array of int64; An Error Range check Error
X: an array of integer; An Error Range check Error
X: an array of smallint; An out of memory

Also is out of memory, why before both the range check error which quote out of the memory

CodePudding user response:

X: an array of integer; An Error Range check Error
X: an array of smallint; An out of memory
X: an array of byte; Normal

Personal understanding, the first one could be syntax check level mistake
The second is grammar by allocating memory but found insufficient

CodePudding user response:

With the size of the memory
  • Related