'undefined opcode (init)'

Postby Mikael on Thu Sep 11, 2003 10:53 am

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,

Posts: 156
Joined: Sun Apr 13, 2003 9:19 am
Location: Denmark

Postby jstadolnik on Thu Sep 11, 2003 12:52 pm

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.
Posts: 1741
Joined: Wed Dec 06, 2000 3:34 am
Location: USA

Postby wolfgang on Thu Sep 11, 2003 3:44 pm

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! - http://www.pdamusician.com
Composing music on the PocketPC! - http://www.pdamusician.com
Posts: 281
Joined: Tue Dec 12, 2000 4:22 am
Location: USA

Return to PocketC for Palm OS KB

Who is online

Users browsing this forum: No registered users and 1 guest