max length of all arrays = 255 ?

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

max length of all arrays = 255 ?

Post by HaWe »

hi,
just to be sure:
is the max length of both arrays of char and arrays of int (1-dimensional) limited to 255?
if yes:
is there a way to use structs or anything else to get a length of 512...1024 in 1 series?
spillerrec
Posts: 358
Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:

Re: max length of all arrays = 255 ?

Post by spillerrec »

No, there should not be such limitations, the only limitation is the amount of RAM available iirc. I have used way larger arrays than that at least (loading it at run-time from a file). Are you experiencing any issues with large arrays?
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: max length of all arrays = 255 ?

Post by HaWe »

EDIT:
spiller, you're absolutely right, I tried a short test and myarray[500] works with both int and char.
The bug must have been somewhere else in my program.
Thx for your reply!
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: max length of all arrays = 255 ?

Post by afanofosc »

As mentioned, arrays can be much longer than 255. You have a total of 32k of memory available for all the variables in your program. In theory you could write a program that gave nearly all of that to one large array. If it was an array of longs then you could have close to 8k elements. In practice there are a number of variables getting used behind the scenes and any strings you use would take up array space also, even if they are constants, so you won't be able to dedicate all 32k to arrays. And if you try to manipulate the array at all it will require copies of it, etc... Keep that in mind.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: max length of all arrays = 255 ?

Post by HaWe »

yes, thx, as mentioned I already found out that is actually was a bug in my original source code. :)
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 0 guests