maximum array size

Just starting out? Need help? Post your questions and find answers here.
fcb
User
User
Posts: 42
Joined: Fri Aug 31, 2012 10:12 pm

maximum array size

Post by fcb »

Is there a maximum array size?

I have an string array that seems to cause an "Array index out of bounds" error when it exceeds approx 1500x576. Each field can be a string around 5-20 charaters long.
User avatar
Demivec
Addict
Addict
Posts: 4089
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: maximum array size

Post by Demivec »

fcb wrote:Is there a maximum array size?

I have an string array that seems to cause an "Array index out of bounds" error when it exceeds approx 1500x576. Each field can be a string around 5-20 charaters long.
Can you post a short code sample where this happens?

Here's some sample code, what does it show for you?

Code: Select all

Define colSize = 1500, rowSize = 576

Repeat
  Dim  a$(colSize, rowSize)
  a$(colSize, rowSize) = "Test assignment at string array element (" + colSize + ", " + rowSize + ")"
  Debug a$(colSize, rowSize)
  colSize + Random(3000, 1500)
  rowSize + Random(3000, 1500)
ForEver
For me, testing the above code the program seems to stall after this output:

Code: Select all

Test assignment at string array element (1500, 576)
Test assignment at string array element (4223, 3480)
Test assignment at string array element (7039, 6319)
Test assignment at string array element (9909, 9032)
Test assignment at string array element (12558, 11941)
Test assignment at string array element (15500, 14833)
Test assignment at string array element (18069, 17465)
Test assignment at string array element (21043, 20051)
Test assignment at string array element (23934, 22627)
Test assignment at string array element (26735, 25169)
Test assignment at string array element (29492, 27688)
Test assignment at string array element (32323, 30250)
Test assignment at string array element (35044, 32995)
Test assignment at string array element (37860, 35852)
With the following test code:

Code: Select all

Define colSize = 1500, rowSize = 1

Repeat
  Dim  a$(colSize, rowSize)
  a$(colSize, rowSize) = "Test assignment at string array element (" + colSize + ", " + rowSize + ")"
  Debug a$(colSize, rowSize)
  colSize + Random(3000000, 2500000)
ForEver
I get this output, before I stopped the program:

Code: Select all

Test assignment at string array element (1500, 1)
Test assignment at string array element (2531481, 1)
Test assignment at string array element (5429027, 1)
Test assignment at string array element (8397942, 1)
Test assignment at string array element (11025759, 1)
Test assignment at string array element (13557959, 1)
Test assignment at string array element (16219800, 1)
Test assignment at string array element (18784723, 1)
-------------- snipped output
...
-------------- snipped output
Test assignment at string array element (243473889, 1)
Test assignment at string array element (246152615, 1)
Test assignment at string array element (248816918, 1)
Test assignment at string array element (251799022, 1)
Test assignment at string array element (254363155, 1)
Test assignment at string array element (257175772, 1)
Test assignment at string array element (259725249, 1)
Test assignment at string array element (262584390, 1)
I don't see an immediate limitation imposed on the maximum array size.

Running PB v 5.72 b3 LTS under Windows 10 x64 with 16GB ram.

You frankly seem to have the 'Array index out of bounds' :mrgreen: . This would be due to using an index that was too large (or too small). Check your indexes in the line where the error is against the Dim size. If it is always the same line, use CallDebugger before it and examine the array size at that time along with the indexes you used. If you ReDim the array smaller you may be using an old index value that is no longer within the bounds of the new size.
BarryG
Addict
Addict
Posts: 3318
Joined: Thu Apr 18, 2019 8:17 am

Re: maximum array size

Post by BarryG »

fcb wrote:Is there a maximum array size?
No.
fcb wrote:"Array index out of bounds" error
That just means you're trying to use an index that is higher than what you Dim'ed. In other words, it's a coding error by you rather than an array limit. For example, if you used Dim(1500,576) and then tried to use index (1501,576).
fcb
User
User
Posts: 42
Joined: Fri Aug 31, 2012 10:12 pm

Re: maximum array size

Post by fcb »

Thank you all.

The problem was (obviously) with me and my code - now resolved. It's good to know that there isn't a built in limit, thanks for the test code.
Post Reply