Page 1 of 1

PostPosted: Thu Sep 11, 2003 10:53 am
by Mikael
I'm currently using a 1000x4 array which I'm trying to increase in size. the trouble is I can't get it any bigger than 1023x4 without receiving a message at runtime saying 'undefined opcode' (init address, blah, blah). I also have a couple of other 1 dimensional arrays within init(). Have I reached the size limit for the array function in Ptoolbox? I was told that the size limit was 8000 elements.

Thanks in advance,


PostPosted: Thu Sep 11, 2003 12:52 pm
by jstadolnik
You are very likely running into the PocketC 8000 dynamic element limitation.

Multi-dimensional arrays in PocketC tend to have a lot of overhead in terms of memory usage. For example a 1000x4 array will actually use 1000+(1000*4) memory elements. The first 1000 are used to stored pointers to the later elements.

One way to get around this is to flatten the array and calculate the indexing yourself.

For example:


Is equivalent to:


The first case uses less memory, but is slower.


The PToolboxLib guy.

PostPosted: Thu Sep 11, 2003 3:44 pm
by wolfgang
Another way to reduce the size taken up by those multidimensional arrays is to re-order the dimensions, putting the ones with shortest size first, i.e. use an array of 4x1000 instead of the one with 1000x4 elements. Same goes for more dimensions, e.g. a 5x10x20 array takes up less space than a 20x10x5 element array.

This is because those arrays are implemented as arrays of pointers to arrays of pointers (see the multidimensional array example in the PocketC documentation ts see what I mean).


Composing music on the PocketPC! -