Declaring memory space
pacman
Posts: 327
Can some one tell me how big I can declare an an array in memory?
eg: byte MsgStr[???]
Could the value in the count field be {41*128} = 5248 or even double that?
I have searched the v1.1 manual and the other 2 prop books (and I can not see it anywhere) so if you can also tell me a page number and book that would be brilliant.
And I don't think I can define an array of arrays (eg: AllMsgs[128] of type MsgStr {from above}). My reading suggests I can't, but perhaps I can ?? please advise...
Thanks in advance
eg: byte MsgStr[???]
Could the value in the count field be {41*128} = 5248 or even double that?
I have searched the v1.1 manual and the other 2 prop books (and I can not see it anywhere) so if you can also tell me a page number and book that would be brilliant.
And I don't think I can define an array of arrays (eg: AllMsgs[128] of type MsgStr {from above}). My reading suggests I can't, but perhaps I can ?? please advise...
Thanks in advance
Comments
If your program get's bigger you have less RAM available for an array.
But you also have to take care of the stack that's needed by the initial COG. The initial COG uses the free RAM as stack-space. So, let's say the array uses all available free RAM then there is no stack space for the initial COG left, which can lead to very suspicious bugs.
A two dimensional array is not supported by SPIN syntax. But in all languages available you can create your own 2dimensional array by using a 1dimensional array that has n*m elements. I suppose in your case you want to have access to each string. So you'd have to calculate the address by multiplying the string number with the max. size of a string (41 in your case).
On the other hand an array of an array is nothing else as an array which contains the addresses of the other arrays.
VAR
word AllMsgs[128]
PUB main
AllMsgs[0] := @MsgStr
AllMsgs[1] := @MsgStr + 41
....
Of course you could do this in a loop. But from my point of view this only makes sense if you want to save memory by not wasting 20 bytes in case the string is only 20 characters long (+ 1 byte for stringend).
Otherwise the calculation is easier.
Just to add, is memory precious?
If your longest string is 41 bytes and you define your list as 128 strings, then as MagIO2 says, to get a string just multiply n by 41.
But - maybe you are running out of memory?
If so - lots of options. Put the strings in high eeprom (32-64k). Or add an SD card. Or add external memory.
But if there is plenty of code space left even after using 5k or 10k of space, then just define the arrays, fill them up and it should all work fine.