Home AMX User Forum NetLinx Studio

SET_LENGTH_ARRAY Problems

Has anybody had problems using the above command? I have a structure array that stores information from an imerge soundserver, the module requests # of albums from the server and stores that in a level, the level event then sets the length of the array to = #albums and then sends the request to populate the array with data.

Problem is the array always gets set to a length of 1...

I am not sure where to start looking for a resolution so not sure what other info to provide but any suggestions as to where to start on the would be much appreciated.

Phil

Comments

  • To use SET_LENGTH_ARRAY (and similar SET_LENGTH_STRING), you first must have an array with enough size from start. SET_LENGTH_ARRAY() and SET_LENGTH_STRING() only can operate within that "predefined" range of elements, the commands can not size up an array of lets say 100 elements to 200, but only set up or down within the predefined 100 elements.
    DEFINE_STRUCTURE
    STRUCTURE _sMyStruct
    {
    CHAR ElementOne[50]
    INTEGER Element2
    }
    
    DEFINE_VARIABLE
    _sMyStruct MyStruct[100]
    
    ...
    
    DEFINE_PROGRAM
    PUSH[dvPanel,1]
    {
    // Set MyStruct to the # of albums,
    // but can NOT be larger as the # of elements defined in DEFINE_VARIABLE
    SET_LENGTH_ARRAY(MyStruct,AlbumCount)
    
    // set it back to maximum size
    SET_LENGTH_ARRAY(MyStruct,MAX_LENGTH_ARRAY(MyStruct))
    }
    

    It's the same with SET_LENGTH_STRING(), both instructions doing absolutely the same.

    Hope this helps.
  • hodeyphodeyp Posts: 104
    many thanks, I thought I was going mad!

    Is there no way of dynamically adjusting the size of an array? Seems to be a waste of resources having to set an array to maximum ever expected size just in case...
  • hodeyp wrote:
    many thanks, I thought I was going mad!

    Is there no way of dynamically adjusting the size of an array? Seems to be a waste of resources having to set an array to maximum ever expected size just in case...

    No. Memory is checked and allocated at compilerrun, so it's not possible to size up. We may have always some resources wasted, but if working in VOLATILE mem (16..64MByte depending on master hardware) this should not be that problem :)
  • alexanboalexanbo Posts: 282
    I think theoretically in Duet you should be able to use collections and such for dynamic sized storage, of course then you have to load the duet components so that probably doesn't save any space....
Sign In or Register to comment.